@@ -1551,7 +1551,7 @@ static void mg_snprintf(const struct mg_connection *conn,
15511551#if defined(vsnprintf)
15521552#undef vsnprintf
15531553#endif
1554- #ifndef NDEBUG
1554+ #if !defined( NDEBUG)
15551555#define malloc DO_NOT_USE_THIS_FUNCTION__USE_mg_malloc
15561556#define calloc DO_NOT_USE_THIS_FUNCTION__USE_mg_calloc
15571557#define realloc DO_NOT_USE_THIS_FUNCTION__USE_mg_realloc
@@ -6213,13 +6213,18 @@ push_inner(struct mg_context *ctx,
62136213 /* For sockets, wait for the socket using poll */
62146214 struct mg_pollfd pfd[2];
62156215 int pollres;
6216+ unsigned int num_sock = 1;
62166217
62176218 pfd[0].fd = sock;
62186219 pfd[0].events = POLLOUT;
62196220
6220- pfd[1].fd = ctx->thread_shutdown_notification_socket;
6221- pfd[1].events = POLLIN;
6222- pollres = mg_poll(pfd, 2, (int)(ms_wait), &(ctx->stop_flag));
6221+ if (ctx->context_type == CONTEXT_SERVER) {
6222+ pfd[num_sock].fd = ctx->thread_shutdown_notification_socket;
6223+ pfd[num_sock].events = POLLIN;
6224+ num_sock++;
6225+ }
6226+
6227+ pollres = mg_poll(pfd, num_sock, (int)(ms_wait), &(ctx->stop_flag));
62236228 if (!STOP_FLAG_IS_ZERO(&ctx->stop_flag)) {
62246229 return -2;
62256230 }
@@ -6330,6 +6335,7 @@ pull_inner(FILE *fp,
63306335 struct mg_pollfd pfd[2];
63316336 int to_read;
63326337 int pollres;
6338+ unsigned int num_sock = 1;
63336339
63346340 to_read = mbedtls_ssl_get_bytes_avail(conn->ssl);
63356341
@@ -6345,13 +6351,17 @@ pull_inner(FILE *fp,
63456351 pfd[0].fd = conn->client.sock;
63466352 pfd[0].events = POLLIN;
63476353
6348- pfd[1].fd = conn->phys_ctx->thread_shutdown_notification_socket;
6349- pfd[1].events = POLLIN;
6354+ if (conn->phys_ctx->context_type == CONTEXT_SERVER) {
6355+ pfd[num_sock].fd =
6356+ conn->phys_ctx->thread_shutdown_notification_socket;
6357+ pfd[num_sock].events = POLLIN;
6358+ num_sock++;
6359+ }
63506360
63516361 to_read = len;
63526362
63536363 pollres = mg_poll(pfd,
6354- 2 ,
6364+ num_sock ,
63556365 (int)(timeout * 1000.0),
63566366 &(conn->phys_ctx->stop_flag));
63576367
@@ -6388,6 +6398,7 @@ pull_inner(FILE *fp,
63886398 int ssl_pending;
63896399 struct mg_pollfd pfd[2];
63906400 int pollres;
6401+ unsigned int num_sock = 1;
63916402
63926403 if ((ssl_pending = SSL_pending(conn->ssl)) > 0) {
63936404 /* We already know there is no more data buffered in conn->buf
@@ -6400,11 +6411,16 @@ pull_inner(FILE *fp,
64006411 } else {
64016412 pfd[0].fd = conn->client.sock;
64026413 pfd[0].events = POLLIN;
6403- pfd[1].fd = conn->phys_ctx->thread_shutdown_notification_socket;
6404- pfd[1].events = POLLIN;
6414+
6415+ if (conn->phys_ctx->context_type == CONTEXT_SERVER) {
6416+ pfd[num_sock].fd =
6417+ conn->phys_ctx->thread_shutdown_notification_socket;
6418+ pfd[num_sock].events = POLLIN;
6419+ num_sock++;
6420+ }
64056421
64066422 pollres = mg_poll(pfd,
6407- 2 ,
6423+ num_sock ,
64086424 (int)(timeout * 1000.0),
64096425 &(conn->phys_ctx->stop_flag));
64106426 if (!STOP_FLAG_IS_ZERO(&conn->phys_ctx->stop_flag)) {
@@ -6444,15 +6460,20 @@ pull_inner(FILE *fp,
64446460 } else {
64456461 struct mg_pollfd pfd[2];
64466462 int pollres;
6463+ unsigned int num_sock = 1;
64476464
64486465 pfd[0].fd = conn->client.sock;
64496466 pfd[0].events = POLLIN;
64506467
6451- pfd[1].fd = conn->phys_ctx->thread_shutdown_notification_socket;
6452- pfd[1].events = POLLIN;
6468+ if (conn->phys_ctx->context_type == CONTEXT_SERVER) {
6469+ pfd[num_sock].fd =
6470+ conn->phys_ctx->thread_shutdown_notification_socket;
6471+ pfd[num_sock].events = POLLIN;
6472+ num_sock++;
6473+ }
64536474
64546475 pollres = mg_poll(pfd,
6455- 2 ,
6476+ num_sock ,
64566477 (int)(timeout * 1000.0),
64576478 &(conn->phys_ctx->stop_flag));
64586479 if (!STOP_FLAG_IS_ZERO(&conn->phys_ctx->stop_flag)) {
@@ -10323,8 +10344,11 @@ send_file_data(struct mg_connection *conn,
1032310344 }
1032410345
1032510346 /* Read from file, exit the loop on error */
10326- if ((num_read =
10327- pull_inner(filep->access.fp, NULL, buf, to_read, /* unused */ 0.0))
10347+ if ((num_read = pull_inner(filep->access.fp,
10348+ NULL,
10349+ buf,
10350+ to_read,
10351+ /* unused */ 0.0))
1032810352 <= 0) {
1032910353 break;
1033010354 }
@@ -10957,7 +10981,7 @@ parse_http_headers(char **buf, struct mg_header hdr[MG_MAX_HEADERS])
1095710981 }
1095810982
1095910983 /* here *dp is either 0 or '\n' */
10960- /* in any case, we have a new header */
10984+ /* in any case, we have found a complete header */
1096110985 num_headers = i + 1;
1096210986
1096310987 if (*dp) {
@@ -10966,9 +10990,11 @@ parse_http_headers(char **buf, struct mg_header hdr[MG_MAX_HEADERS])
1096610990 *buf = dp;
1096710991
1096810992 if ((dp[0] == '\r') || (dp[0] == '\n')) {
10969- /* This is the end of the header */
10993+ /* We've had CRLF twice in a row
10994+ * This is the end of the headers */
1097010995 break;
1097110996 }
10997+ /* continue within the loop, find the next header */
1097210998 } else {
1097310999 *buf = dp;
1097411000 break;
@@ -16787,16 +16813,24 @@ sslize(struct mg_connection *conn,
1678716813 * This is typical for non-blocking sockets. */
1678816814 struct mg_pollfd pfd[2];
1678916815 int pollres;
16816+ unsigned int num_sock = 1;
1679016817 pfd[0].fd = conn->client.sock;
1679116818 pfd[0].events = ((err == SSL_ERROR_WANT_CONNECT)
1679216819 || (err == SSL_ERROR_WANT_WRITE))
1679316820 ? POLLOUT
1679416821 : POLLIN;
1679516822
16796- pfd[1].fd =
16797- conn->phys_ctx->thread_shutdown_notification_socket;
16798- pfd[1].events = POLLIN;
16799- pollres = mg_poll(pfd, 2, 50, &(conn->phys_ctx->stop_flag));
16823+ if (conn->phys_ctx->context_type == CONTEXT_SERVER) {
16824+ pfd[num_sock].fd =
16825+ conn->phys_ctx->thread_shutdown_notification_socket;
16826+ pfd[num_sock].events = POLLIN;
16827+ num_sock++;
16828+ }
16829+
16830+ pollres = mg_poll(pfd,
16831+ num_sock,
16832+ 50,
16833+ &(conn->phys_ctx->stop_flag));
1680016834 if (pollres < 0) {
1680116835 /* Break if error occurred (-1)
1680216836 * or server shutdown (-2) */
0 commit comments