浏览代码

Fix mg_poll for infinite timeouts

bel 8 年之前
父节点
当前提交
c20ec63378
共有 1 个文件被更改,包括 8 次插入2 次删除
  1. 8 2
      src/civetweb.c

+ 8 - 2
src/civetweb.c

@@ -4177,7 +4177,7 @@ mg_poll(struct pollfd *pfd,
 			return -2;
 		}
 
-		if (milliseconds < ms_now) {
+		if ((milliseconds >= 0) && (milliseconds < ms_now)) {
 			ms_now = milliseconds;
 		}
 
@@ -4189,7 +4189,9 @@ mg_poll(struct pollfd *pfd,
 		}
 
 		/* Poll returned timeout (0). */
-		milliseconds -= ms_now;
+        if (milliseconds >= 0) {
+		    milliseconds -= ms_now;
+        }
 
 	} while (milliseconds > 0);
 
@@ -4459,6 +4461,10 @@ pull(FILE *fp, struct mg_connection *conn, char *buf, int len, double timeout)
 			} else if (err == WSAETIMEDOUT) {
 				/* TODO: check if this is still required */
 				/* timeout is handled by the while loop  */
+                return 0;
+            } else if (err == WSAECONNABORTED) {
+                /* See https://www.chilkatsoft.com/p/p_299.asp */
+                return -1;
 			} else {
 				DEBUG_TRACE("recv() failed, error %d", err);
 				return -1;