Jelajahi Sumber

More accurate conditions in sockmap's main event loop

z3APA3A 5 tahun lalu
induk
melakukan
b2f82ed04f
1 mengubah file dengan 20 tambahan dan 8 penghapusan
  1. 20 8
      src/sockmap.c

+ 20 - 8
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 *)&param->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 *)&param->sinsr, &sasize);
 			if(res <= 0) {
-				if(res == 0 || !errno) SERVERTERM = 1;
 				FROMSERVER = 0;
+				if(res == 0) {
+					SERVERTERM = 1;
+					continue;
+				}
 			}
 			else {
 #ifdef WITHLOG