bel2125 6 лет назад
Родитель
Сommit
5475c99e94
4 измененных файлов с 38 добавлено и 30 удалено
  1. 21 20
      examples/embedded_c/embedded_c.c
  2. 8 4
      src/civetweb.c
  3. 3 3
      src/handle_form.inl
  4. 6 3
      src/main.c

+ 21 - 20
examples/embedded_c/embedded_c.c

@@ -957,34 +957,35 @@ main(int argc, char *argv[])
 {
 	const char *options[] = {
 #if !defined(NO_FILES)
-	    "document_root",
-	    DOCUMENT_ROOT,
+		"document_root",
+		DOCUMENT_ROOT,
 #endif
-	    "listening_ports",
-	    PORT,
-	    "request_timeout_ms",
-	    "10000",
-	    "error_log_file",
-	    "error.log",
+		"listening_ports",
+		PORT,
+		"request_timeout_ms",
+		"10000",
+		"error_log_file",
+		"error.log",
 #ifdef USE_WEBSOCKET
-	    "websocket_timeout_ms",
-	    "3600000",
+		"websocket_timeout_ms",
+		"3600000",
 #endif
 #ifndef TEST_WITHOUT_SSL
-	    "ssl_certificate",
-	    "../../resources/cert/server.pem",
-	    "ssl_protocol_version",
-	    "3",
-	    "ssl_cipher_list",
+		"ssl_certificate",
+		"../../resources/cert/server.pem",
+		"ssl_protocol_version",
+		"3",
+		"ssl_cipher_list",
 #ifdef USE_SSL_DH
-	    "ECDHE-RSA-AES256-GCM-SHA384:DES-CBC3-SHA:AES128-SHA:AES128-GCM-SHA256",
+		"ECDHE-RSA-AES256-GCM-SHA384:DES-CBC3-SHA:AES128-SHA:AES128-GCM-SHA256",
 #else
-	    "DES-CBC3-SHA:AES128-SHA:AES128-GCM-SHA256",
+		"DES-CBC3-SHA:AES128-SHA:AES128-GCM-SHA256",
 #endif
 #endif
-	    "enable_auth_domain_check",
-	    "no",
-	    0};
+		"enable_auth_domain_check",
+		"no",
+		0
+	};
 	struct mg_callbacks callbacks;
 	struct mg_context *ctx;
 	struct mg_server_port ports[32];

+ 8 - 4
src/civetweb.c

@@ -10597,9 +10597,7 @@ forward_body_data(struct mg_connection *conn, FILE *fp, SOCKET sock, SSL *ssl)
 	if ((expect != NULL) && (mg_strcasecmp(expect, "100-continue") != 0)) {
 		/* Client sent an "Expect: xyz" header and xyz is not 100-continue.
 		 */
-		mg_send_http_error(conn,
-		                   417,
-		                   "Error: Can not fulfill expectation");
+		mg_send_http_error(conn, 417, "Error: Can not fulfill expectation");
 	} else {
 		if (expect != NULL) {
 			(void)mg_printf(conn, "%s", "HTTP/1.1 100 Continue\r\n\r\n");
@@ -15144,12 +15142,18 @@ sslize(struct mg_connection *conn,
 					 * See https://linux.die.net/man/3/ssl_get_error
 					 * This is typical for non-blocking sockets. */
 					struct mg_pollfd pfd;
+					int pollres;
 					pfd.fd = conn->client.sock;
 					pfd.events = ((err == SSL_ERROR_WANT_CONNECT)
 					              || (err == SSL_ERROR_WANT_WRITE))
 					                 ? POLLOUT
 					                 : POLLIN;
-					mg_poll(&pfd, 1, 50, stop_server);
+					pollres = mg_poll(&pfd, 1, 50, stop_server);
+					if (pollres < 0) {
+						/* Break if error occured (-1)
+						 * or server shutdown (-2) */
+						break;
+					}
 				}
 
 			} else if (err == SSL_ERROR_SYSCALL) {

+ 3 - 3
src/handle_form.inl

@@ -188,8 +188,8 @@ mg_handle_form_request(struct mg_connection *conn,
 	    (conn->request_info.content_length > 0) || (conn->is_chunked);
 
 	/* Unused without filesystems */
-	(void) fstore;
-	(void) file_size;
+	(void)fstore;
+	(void)file_size;
 
 	/* There are three ways to encode data from a HTML form:
 	 * 1) method: GET (default)
@@ -661,7 +661,7 @@ mg_handle_form_request(struct mg_connection *conn,
 			size_t to_read = sizeof(buf) - 1 - (size_t)buf_fill;
 
 			/* Unused without filesystems */
-			(void) n;
+			(void)n;
 
 			r = mg_read(conn, buf + (size_t)buf_fill, to_read);
 			if ((r < 0) || ((r == 0) && all_data_read)) {

+ 6 - 3
src/main.c

@@ -2985,13 +2985,15 @@ main(int argc, char *argv[])
 @end
 
 @implementation Civetweb
-- (void)openBrowser {
+- (void)openBrowser
+{
 	[[NSWorkspace sharedWorkspace]
 	    openURL:[NSURL URLWithString:[NSString stringWithUTF8String:
 	                                               get_url_to_first_open_port(
 	                                                   g_ctx)]]];
 }
-- (void)editConfig {
+- (void)editConfig
+{
 	create_config_file(g_ctx, g_config_file_name);
 	NSString *path = [NSString stringWithUTF8String:g_config_file_name];
 	if (![[NSWorkspace sharedWorkspace] openFile:path
@@ -3004,7 +3006,8 @@ main(int argc, char *argv[])
 		(void)[alert runModal];
 	}
 }
-- (void)shutDown {
+- (void)shutDown
+{
 	[NSApp terminate:nil];
 }
 @end