From 8975b00cce0b168252fb28309454a3e3076e60ec Mon Sep 17 00:00:00 2001 From: z3APA3A <3APA3A@3proxy.ru> Date: Wed, 11 Jun 2014 01:54:25 +0400 Subject: [PATCH] better EINTR handling --- src/sockgetchar.c | 2 +- src/sockmap.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/sockgetchar.c b/src/sockgetchar.c index 1000d2c..906a4bd 100644 --- a/src/sockgetchar.c +++ b/src/sockgetchar.c @@ -47,7 +47,7 @@ int socksendto(SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufs if(res < 1) break; res = so._sendto(sock, buf + sent, bufsize - sent, 0, sin, SASIZE(sin)); if(res < 0) { - if(errno != EAGAIN) break; + if(errno != EAGAIN && errno != EINTR) break; continue; } sent += res; diff --git a/src/sockmap.c b/src/sockmap.c index 24fe342..5626d3d 100644 --- a/src/sockmap.c +++ b/src/sockmap.c @@ -130,7 +130,8 @@ int sockmap(struct clientparam * param, int timeo){ } res = so._sendto(param->clisock, param->srvbuf + param->srvoffset,(!param->waitserver64 || (param->waitserver64 - received) > (param->srvinbuf - param->srvoffset))? param->srvinbuf - param->srvoffset : (int)(param->waitserver64 - received), 0, (struct sockaddr*)¶m->sincr, sasize); if(res < 0) { - if(errno != EAGAIN) return 96; + if(errno != EAGAIN && errno != EINTR) return 96; + if(errno == EINTR) usleep(SLEEPTIME); continue; } param->srvoffset += res; @@ -155,7 +156,8 @@ int sockmap(struct clientparam * param, int timeo){ } res = so._sendto(param->remsock, param->clibuf + param->clioffset, (!param->waitclient64 || (param->waitclient64 - sent) > (param->cliinbuf - param->clioffset))? param->cliinbuf - param->clioffset : (int)(param->waitclient64 - sent), 0, (struct sockaddr*)¶m->sins, sasize); if(res < 0) { - if(errno != EAGAIN) return 97; + if(errno != EAGAIN && errno != EINTR) return 97; + if(errno == EINTR) usleep(SLEEPTIME); continue; } param->clioffset += res; @@ -180,7 +182,8 @@ int sockmap(struct clientparam * param, int timeo){ } else { if (res < 0){ - if( errno != EAGAIN) return (94); + if(errno != EAGAIN && errno != EINTR) return 94; + if(errno == EINTR) usleep(SLEEPTIME); continue; } param->cliinbuf += res; @@ -210,7 +213,8 @@ int sockmap(struct clientparam * param, int timeo){ } else { if (res < 0){ - if( errno != EAGAIN) return (93); + if(errno != EAGAIN && errno != EINTR) return 93; + if(errno == EINTR) usleep(SLEEPTIME); continue; } param->srvinbuf += res;