From 677ed39c8f88ee14801c43677668bf2db662669b Mon Sep 17 00:00:00 2001 From: z3APA3A <3APA3A@3proxy.ru> Date: Mon, 19 Oct 2020 13:03:55 +0300 Subject: [PATCH] More accurate conditions in sockmap's main event loop --- src/sockmap.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/sockmap.c b/src/sockmap.c index 7c84e92..61f020f 100644 --- a/src/sockmap.c +++ b/src/sockmap.c @@ -123,17 +123,17 @@ int sockmap(struct clientparam * param, int timeo, int usesplice){ if(action != PASS) RETURN(19); while( - ((!CLIENTTERM) && (inserverbuf + ((!CLIENTTERM) && fromserver && (inserverbuf #ifdef WITHSPLICE || inserverpipe #endif - || (!SERVERTERM && fromserver))) + || (!SERVERTERM ))) || - ((!SERVERTERM) && (inclientbuf + ((!SERVERTERM) && fromclient && (inclientbuf #ifdef WITHSPLICE || inclientpipe #endif - || (!CLIENTTERM && fromclient))) + || (!CLIENTTERM ))) ){ @@ -316,8 +316,11 @@ log("read from client to pipe"); #ifdef WITHLOG log("read failed"); #endif - if(res == 0 || !errno) CLIENTTERM = 1; FROMCLIENT = TOCLIENTPIPE = 0; + if(res == 0) { + CLIENTTERM = 1; + continue; + } } else { #ifdef WITHLOG @@ -340,8 +343,11 @@ log("read from server to pipe\n"); log("splice finished\n"); #endif if(res <= 0) { - if(res == 0 || !errno) SERVERTERM = 1; FROMSERVER = TOSERVERPIPE = 0; + if(res == 0 || !errno) { + SERVERTERM = 1; + continue; + } } else { #ifdef WITHLOG @@ -375,8 +381,11 @@ log("read from client to buf"); sasize = sizeof(param->sincr); res = so._recvfrom(param->clisock, (char *)param->clibuf + param->cliinbuf, (int)MIN((uint64_t)param->clibufsize - param->cliinbuf, fromclient-inclientbuf), 0, (struct sockaddr *)¶m->sincr, &sasize); if(res <= 0) { - if(res == 0 || !errno)CLIENTTERM = 1; FROMCLIENT = 0; + if(res == 0){ + CLIENTTERM = 1; + continue; + } } else { #ifdef WITHLOG @@ -397,8 +406,11 @@ log("read from server to buf"); sasize = sizeof(param->sinsr); res = so._recvfrom(param->remsock, (char *)param->srvbuf + param->srvinbuf, (int)MIN((uint64_t)param->srvbufsize - param->srvinbuf, fromserver-inserverbuf), 0, (struct sockaddr *)¶m->sinsr, &sasize); if(res <= 0) { - if(res == 0 || !errno) SERVERTERM = 1; FROMSERVER = 0; + if(res == 0) { + SERVERTERM = 1; + continue; + } } else { #ifdef WITHLOG