libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 8cbc64d25218591d2840c1f4b5f12e88278d8bc1
parent 4e1d3bfc1f28f6bb0a2675b6491bc5ecf830d196
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue, 12 Oct 2010 13:45:59 +0000

bugfix

Diffstat:
MChangeLog | 7+++++++
Msrc/daemon/connection.c | 4++--
Msrc/daemon/connection.h | 2+-
Msrc/daemon/connection_https.c | 93++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Msrc/daemon/daemon.c | 15++++++++++++---
5 files changed, 71 insertions(+), 50 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,10 @@ +Tue Oct 12 15:41:51 CEST 2010 + Fixed issue with data received via SSL being delayed in the + GNUtls buffer if sender stopped transmitting (but did not close + the connection) and MHD buffer size was smaller than last fragment, + resulting in possibly significantly delayed processing of + incoming data. -CG + Wed Sep 22 09:48:59 CEST 2010 Changed port argument from 'unsigned short' to 'uint16_t'. Removed dead code when compiling with messages enabled. diff --git a/src/daemon/connection.c b/src/daemon/connection.c @@ -767,7 +767,7 @@ MHD_connection_get_fdset (struct MHD_Connection *connection, * connection is not waiting for any read or write events */ int -MHD_connection_get_pollfd(struct MHD_Connection *connection, struct MHD_Pollfd *p) +MHD_connection_get_pollfd (struct MHD_Connection *connection, struct MHD_Pollfd *p) { int fd; @@ -2264,7 +2264,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) } void -MHD_set_http_calbacks (struct MHD_Connection *connection) +MHD_set_http_callbacks_ (struct MHD_Connection *connection) { connection->read_handler = &MHD_connection_handle_read; connection->write_handler = &MHD_connection_handle_write; diff --git a/src/daemon/connection.h b/src/daemon/connection.h @@ -48,7 +48,7 @@ MHD_connection_get_fdset (struct MHD_Connection *connection, int MHD_connection_get_pollfd(struct MHD_Connection *connection, struct MHD_Pollfd *p); -void MHD_set_http_calbacks (struct MHD_Connection *connection); +void MHD_set_http_callbacks_ (struct MHD_Connection *connection); int MHD_connection_handle_read (struct MHD_Connection *connection); diff --git a/src/daemon/connection_https.c b/src/daemon/connection_https.c @@ -51,50 +51,6 @@ MHD_tls_connection_close (struct MHD_Connection *connection, MHD_connection_close (connection, termination_code); } -/** - * This function was created to handle per-connection processing that - * has to happen even if the socket cannot be read or written to. All - * implementations (multithreaded, external select, internal select) - * call this function. - * - * @param connection being handled - * @return MHD_YES if we should continue to process the - * connection (not dead yet), MHD_NO if it died - */ -static int -MHD_tls_connection_handle_idle (struct MHD_Connection *connection) -{ - unsigned int timeout; - -#if DEBUG_STATES - MHD_DLOG (connection->daemon, "%s: state: %s\n", - __FUNCTION__, MHD_state_to_string (connection->state)); -#endif - timeout = connection->daemon->connection_timeout; - if ((connection->socket_fd != -1) && (timeout != 0) - && (time (NULL) - timeout > connection->last_activity)) - { - MHD_tls_connection_close (connection, - MHD_REQUEST_TERMINATED_TIMEOUT_REACHED); - return MHD_NO; - } - switch (connection->state) - { - /* on newly created connections we might reach here before any reply has been received */ - case MHD_TLS_CONNECTION_INIT: - return MHD_YES; - /* close connection if necessary */ - case MHD_CONNECTION_CLOSED: - if (connection->socket_fd != -1) - MHD_tls_connection_close (connection, - MHD_REQUEST_TERMINATED_COMPLETED_OK); - return MHD_NO; - default: - return MHD_connection_handle_idle (connection); - } - return MHD_YES; -} - /** * This function handles a particular SSL/TLS connection when @@ -193,6 +149,55 @@ MHD_tls_connection_handle_write (struct MHD_Connection *connection) return MHD_connection_handle_write (connection); } + +/** + * This function was created to handle per-connection processing that + * has to happen even if the socket cannot be read or written to. All + * implementations (multithreaded, external select, internal select) + * call this function. + * + * @param connection being handled + * @return MHD_YES if we should continue to process the + * connection (not dead yet), MHD_NO if it died + */ +static int +MHD_tls_connection_handle_idle (struct MHD_Connection *connection) +{ + unsigned int timeout; + +#if DEBUG_STATES + MHD_DLOG (connection->daemon, "%s: state: %s\n", + __FUNCTION__, MHD_state_to_string (connection->state)); +#endif + timeout = connection->daemon->connection_timeout; + if ((connection->socket_fd != -1) && (timeout != 0) + && (time (NULL) - timeout > connection->last_activity)) + { + MHD_tls_connection_close (connection, + MHD_REQUEST_TERMINATED_TIMEOUT_REACHED); + return MHD_NO; + } + switch (connection->state) + { + /* on newly created connections we might reach here before any reply has been received */ + case MHD_TLS_CONNECTION_INIT: + return MHD_YES; + /* close connection if necessary */ + case MHD_CONNECTION_CLOSED: + if (connection->socket_fd != -1) + MHD_tls_connection_close (connection, + MHD_REQUEST_TERMINATED_COMPLETED_OK); + return MHD_NO; + default: + if ( (0 != gnutls_record_check_pending (connection->tls_session)) && + (MHD_YES != MHD_tls_connection_handle_read (connection)) ) + return MHD_NO; + return MHD_connection_handle_idle (connection); + } + return MHD_YES; +} + + /** * Set connection callback function to be used through out * the processing of this secure connection. diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c @@ -883,7 +883,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon) connection->last_activity = time (NULL); /* set default connection handlers */ - MHD_set_http_calbacks (connection); + MHD_set_http_callbacks_ (connection); connection->recv_cls = &recv_param_adapter; connection->send_cls = &send_param_adapter; #if HTTPS_SUPPORT @@ -1062,6 +1062,11 @@ MHD_get_timeout (struct MHD_Daemon *daemon, unsigned long long *timeout) { if (earliest_deadline > pos->last_activity + dto) earliest_deadline = pos->last_activity + dto; +#if HTTPS_SUPPORT + if ( (0 != (daemon->options & MHD_USE_SSL)) && + (0 != gnutls_record_check_pending (pos->tls_session)) ) + earliest_deadline = now; +#endif pos = pos->next; } if (earliest_deadline < now) @@ -1071,6 +1076,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon, unsigned long long *timeout) return MHD_YES; } + /** * Main select call. * @@ -1220,6 +1226,7 @@ MHD_poll (struct MHD_Daemon *daemon) #endif } + /** * Run webserver operations (without blocking unless * in client callbacks). This method should be called @@ -1242,6 +1249,7 @@ MHD_run (struct MHD_Daemon *daemon) return MHD_YES; } + /** * Thread that runs the select loop until the daemon * is explicitly shut down. @@ -1264,6 +1272,7 @@ MHD_select_thread (void *cls) return NULL; } + /** * Start a webserver on the given port. * @@ -1395,7 +1404,7 @@ parse_options_va (struct MHD_Daemon *daemon, break; #if HTTPS_SUPPORT case MHD_OPTION_HTTPS_MEM_KEY: - if (daemon->options & MHD_USE_SSL) + if (0 != (daemon->options & MHD_USE_SSL)) daemon->https_mem_key = va_arg (ap, const char *); #if HAVE_MESSAGES else @@ -1405,7 +1414,7 @@ parse_options_va (struct MHD_Daemon *daemon, #endif break; case MHD_OPTION_HTTPS_MEM_CERT: - if (daemon->options & MHD_USE_SSL) + if (0 != (daemon->options & MHD_USE_SSL)) daemon->https_mem_cert = va_arg (ap, const char *); #if HAVE_MESSAGES else