From 805a64bf2ce5a529fb0d8f53ca584b3d3d2e75a7 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 8 Apr 2017 14:24:04 +0200 Subject: weechat: Handle EINTR without dropping connection --- weechat/tomsg.c | 17 +++++++++++------ 1 file 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 #include #include +#include #include #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){ -- cgit v1.2.3-70-g09d2