Kaynağa Gözat

Do not use consume_socket if the server is to be closed

For the new queue implementation, calling consume_socket is of no use
if the server exit flag is set.

See also #570
bel2125 7 yıl önce
ebeveyn
işleme
b3a76b80ca
1 değiştirilmiş dosya ile 7 ekleme ve 1 silme
  1. 7 1
      src/civetweb.c

+ 7 - 1
src/civetweb.c

@@ -16609,7 +16609,7 @@ produce_socket(struct mg_context *ctx, const struct socket *sp)
 {
 	unsigned int i;
 
-	for (;;) {
+	while (!ctx->stop_flag) {
 		for (i = 0; i < ctx->cfg_worker_threads; i++) {
 			/* find a free worker slot and signal it */
 			if (ctx->client_socks[i].in_use == 0) {
@@ -16778,10 +16778,16 @@ worker_thread_run(struct worker_thread_args *thread_args)
 	conn->conn_state = 1; /* not consumed */
 #endif
 
+#if defined(ALTERNATIVE_QUEUE)
+	while ((ctx->stop_flag == 0)
+	       && consume_socket(ctx, &conn->client, conn->thread_index)) {
+#else
 	/* Call consume_socket() even when ctx->stop_flag > 0, to let it
 	 * signal sq_empty condvar to wake up the master waiting in
 	 * produce_socket() */
 	while (consume_socket(ctx, &conn->client, conn->thread_index)) {
+#endif
+
 		conn->conn_birth_time = time(NULL);
 
 /* Fill in IP, port info early so even if SSL setup below fails,