diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-04-08 14:24:04 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-04-08 14:34:41 +0200 |
commit | 805a64bf2ce5a529fb0d8f53ca584b3d3d2e75a7 (patch) | |
tree | 6f697951b47a2c3a17d1a5cd838bbbc5064c00f8 /weechat | |
parent | 0957cf59225d0ca84afbe679f70d3bd9931b41a7 (diff) |
weechat: Handle EINTR without dropping connection
Diffstat (limited to 'weechat')
-rw-r--r-- | weechat/tomsg.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/weechat/tomsg.c b/weechat/tomsg.c index 9d6f65c..c53a9a0 100644 --- a/weechat/tomsg.c +++ b/weechat/tomsg.c @@ -4,6 +4,7 @@ #include <string.h> #include <sys/socket.h> #include <unistd.h> +#include <errno.h> #include <assert.h> #include "weechat-plugin.h" #include "net.h" @@ -213,12 +214,16 @@ static int fd_hook_callback(const void *conn_vp,void *_d,int fd){ conn->linebuf=realloc(conn->linebuf,conn->linebuf_sz); assert(conn->linebuf); } - i64 nr=recv(fd,conn->linebuf+conn->linebuf_len,conn->linebuf_sz-conn->linebuf_len,0); - if(nr<=0){ - fprintf(debugf,"fd_hook_callback: recv() <= 0\n"); - weechat_printf(NULL,"tomsg: Connection dropped"); - weechat_buffer_close(conn->buffer); - return WEECHAT_RC_OK; + i64 nr; + while(true){ + nr=recv(fd,conn->linebuf+conn->linebuf_len,conn->linebuf_sz-conn->linebuf_len,0); + if(nr<=0){ + if(nr<0&&errno==EINTR)continue; + fprintf(debugf,"fd_hook_callback: recv() <= 0: %s\n",strerror(errno)); + weechat_printf(NULL,"tomsg: Connection dropped"); + weechat_buffer_close(conn->buffer); + return WEECHAT_RC_OK; + } } conn->linebuf_len+=nr; while(true){ |