Explorar el Código

Use non-blocking sockets for http/ws-clients as well

bel hace 8 años
padre
commit
e3a84de89e
Se han modificado 1 ficheros con 15 adiciones y 1 borrados
  1. 15 1
      src/civetweb.c

+ 15 - 1
src/civetweb.c

@@ -4380,7 +4380,7 @@ push(struct mg_context *ctx,
 			}
 		} else
 #endif
-	    if (fp != NULL) {
+		    if (fp != NULL) {
 			n = (int)fwrite(buf, 1, (size_t)len, fp);
 			if (ferror(fp)) {
 				n = -1;
@@ -12378,6 +12378,12 @@ reset_per_request_attributes(struct mg_connection *conn)
 }
 
 
+#if 0
+/* Note: set_sock_timeout is not required for non-blocking sockets.
+ * Leave this function here (commented out) for reference until 
+ * CivetWeb 1.9 is tested, and the tests confirme this function is
+ * no longer required.
+*/
 static int
 set_sock_timeout(SOCKET sock, int milliseconds)
 {
@@ -12418,6 +12424,7 @@ set_sock_timeout(SOCKET sock, int milliseconds)
 
 	return r0 || r1 || r2;
 }
+#endif
 
 
 static int
@@ -12736,6 +12743,10 @@ mg_connect_client_impl(const struct mg_client_options *client_options,
 #endif
 	}
 
+	if (conn) {
+		set_blocking_mode(sock, 0);
+	}
+
 	return conn;
 }
 
@@ -13121,7 +13132,9 @@ mg_get_response(struct mg_connection *conn,
 		if (timeout >= 0) {
 			mg_snprintf(conn, NULL, txt, sizeof(txt), "%i", timeout);
 			rctx.config[REQUEST_TIMEOUT] = txt;
+			/* Not required for non-blocking sockets.
 			set_sock_timeout(conn->client.sock, timeout);
+			*/
 		} else {
 			rctx.config[REQUEST_TIMEOUT] = NULL;
 		}
@@ -13344,6 +13357,7 @@ mg_connect_websocket_client(const char *host,
 		DEBUG_TRACE("%s",
 		            "Websocket client connect thread could not be started\r\n");
 	}
+
 #else
 	/* Appease "unused parameter" warnings */
 	(void)host;