From aeb0f4caa5065c8794283302c2dc7ca5d1c79b4f Mon Sep 17 00:00:00 2001 From: z3APA3A <3APA3A@3proxy.ru> Date: Thu, 15 Oct 2020 16:25:37 +0300 Subject: [PATCH] Better handle socket closing --- src/sockmap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sockmap.c b/src/sockmap.c index 8e1c1f5..c20a7bf 100644 --- a/src/sockmap.c +++ b/src/sockmap.c @@ -314,6 +314,7 @@ log("read from client to pipe"); #ifdef WITHLOG log("read failed"); #endif + if(res == 0 || !errno) CLIENTTERM = 1; FROMCLIENT = TOCLIENTPIPE = 0; } else { @@ -337,6 +338,7 @@ log("read from server to pipe\n"); log("splice finished\n"); #endif if(res <= 0) { + if(res == 0 || !errno) SERVERTERM = 1; FROMSERVER = TOSERVERPIPE = 0; } else { @@ -371,7 +373,7 @@ 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(!errno)CLIENTTERM = 1; + if(res == 0 || !errno)CLIENTTERM = 1; FROMCLIENT = 0; } else { @@ -393,7 +395,7 @@ 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(!errno) SERVERTERM = 1; + if(res == 0 || !errno) SERVERTERM = 1; FROMSERVER = 0; } else {