aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/connection.c')
-rw-r--r--src/microhttpd/connection.c97
1 files changed, 65 insertions, 32 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index de67f800..984c9247 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -2017,6 +2017,46 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
2017 2017
2018 2018
2019/** 2019/**
2020 * Clean up the state of the given connection and move it into the
2021 * clean up queue for final disposal.
2022 *
2023 * @param connection handle for the connection to clean up
2024 */
2025static void
2026cleanup_connection (struct MHD_Connection *connection)
2027{
2028 struct MHD_Daemon *daemon = connection->daemon;
2029
2030 if (NULL != connection->response)
2031 {
2032 MHD_destroy_response (connection->response);
2033 connection->response = NULL;
2034 }
2035 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2036 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
2037 MHD_PANIC ("Failed to acquire cleanup mutex\n");
2038 if (connection->connection_timeout == daemon->connection_timeout)
2039 XDLL_remove (daemon->normal_timeout_head,
2040 daemon->normal_timeout_tail,
2041 connection);
2042 else
2043 XDLL_remove (daemon->manual_timeout_head,
2044 daemon->manual_timeout_tail,
2045 connection);
2046 DLL_remove (daemon->connections_head,
2047 daemon->connections_tail,
2048 connection);
2049 DLL_insert (daemon->cleanup_head,
2050 daemon->cleanup_tail,
2051 connection);
2052 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2053 (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex)) )
2054 MHD_PANIC ("Failed to release cleanup mutex\n");
2055 connection->in_idle = MHD_NO;
2056}
2057
2058
2059/**
2020 * This function was created to handle per-connection processing that 2060 * This function was created to handle per-connection processing that
2021 * has to happen even if the socket cannot be read or written to. 2061 * has to happen even if the socket cannot be read or written to.
2022 * 2062 *
@@ -2378,7 +2418,8 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2378 } 2418 }
2379 continue; 2419 continue;
2380 case MHD_CONNECTION_CLOSED: 2420 case MHD_CONNECTION_CLOSED:
2381 goto cleanup_connection; 2421 cleanup_connection (connection);
2422 return MHD_NO;
2382 default: 2423 default:
2383 EXTRA_CHECK (0); 2424 EXTRA_CHECK (0);
2384 break; 2425 break;
@@ -2431,8 +2472,28 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2431 /* This connection is finished, nothing left to do */ 2472 /* This connection is finished, nothing left to do */
2432 break; 2473 break;
2433 } 2474 }
2475#if EPOLL_SUPPORT
2476 return MHD_connection_epoll_update_ (connection);
2477#else
2478 return MHD_YES;
2479#endif
2480}
2481
2434 2482
2435#if EPOLL_SUPPORT 2483#if EPOLL_SUPPORT
2484/**
2485 * Perform epoll processing, possibly moving the connection back into
2486 * the epoll set if needed.
2487 *
2488 * @param connection connection to process
2489 * @return MHD_YES if we should continue to process the
2490 * connection (not dead yet), MHD_NO if it died
2491 */
2492int
2493MHD_connection_epoll_update_ (struct MHD_Connection *connection)
2494{
2495 struct MHD_Daemon *daemon = connection->daemon;
2496
2436 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && 2497 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
2437 (0 == (connection->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) && 2498 (0 == (connection->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) &&
2438 ( (0 == (connection->epoll_state & MHD_EPOLL_STATE_WRITE_READY)) || 2499 ( (0 == (connection->epoll_state & MHD_EPOLL_STATE_WRITE_READY)) ||
@@ -2457,43 +2518,15 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2457 STRERROR (errno)); 2518 STRERROR (errno));
2458#endif 2519#endif
2459 connection->state = MHD_CONNECTION_CLOSED; 2520 connection->state = MHD_CONNECTION_CLOSED;
2460 goto cleanup_connection; 2521 cleanup_connection (connection);
2522 return MHD_NO;
2461 } 2523 }
2462 connection->epoll_state |= MHD_EPOLL_STATE_IN_EPOLL_SET; 2524 connection->epoll_state |= MHD_EPOLL_STATE_IN_EPOLL_SET;
2463 } 2525 }
2464#endif
2465 connection->in_idle = MHD_NO; 2526 connection->in_idle = MHD_NO;
2466 return MHD_YES; 2527 return MHD_YES;
2467
2468 cleanup_connection:
2469 if (NULL != connection->response)
2470 {
2471 MHD_destroy_response (connection->response);
2472 connection->response = NULL;
2473 }
2474 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2475 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
2476 MHD_PANIC ("Failed to acquire cleanup mutex\n");
2477 if (connection->connection_timeout == daemon->connection_timeout)
2478 XDLL_remove (daemon->normal_timeout_head,
2479 daemon->normal_timeout_tail,
2480 connection);
2481 else
2482 XDLL_remove (daemon->manual_timeout_head,
2483 daemon->manual_timeout_tail,
2484 connection);
2485 DLL_remove (daemon->connections_head,
2486 daemon->connections_tail,
2487 connection);
2488 DLL_insert (daemon->cleanup_head,
2489 daemon->cleanup_tail,
2490 connection);
2491 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
2492 (0 != pthread_mutex_unlock(&daemon->cleanup_connection_mutex)) )
2493 MHD_PANIC ("Failed to release cleanup mutex\n");
2494 connection->in_idle = MHD_NO;
2495 return MHD_NO;
2496} 2528}
2529#endif
2497 2530
2498 2531
2499/** 2532/**