libmicrohttpd

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

commit 76500135fe570921bc86093bb84872e17f1fe1cb
parent 7d4e3953b7667c87a766c9665d49458d2e60f229
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Thu, 16 Mar 2017 21:48:59 +0300

Update connection last activity if and only if any data was received or transmitted.

Diffstat:
MChangeLog | 4++++
Msrc/microhttpd/connection.c | 16++++++++++------
Msrc/microhttpd/connection_https.c | 2+-
3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,7 @@ +Thu Mar 16 21:05:08 MSK 2017 + Fixed minor bug resulted in slight slowdown of HTTPS connection + handshake. -EG + Thu Mar 16 20:35:59 MSK 2017 Improved thread-safety for DL-lists. -EG diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -2405,7 +2405,6 @@ MHD_update_last_activity_ (struct MHD_Connection *connection) int MHD_connection_handle_read (struct MHD_Connection *connection) { - MHD_update_last_activity_ (connection); if ( (MHD_CONNECTION_CLOSED == connection->state) || (connection->suspended) ) return MHD_YES; @@ -2416,6 +2415,7 @@ MHD_connection_handle_read (struct MHD_Connection *connection) try_grow_read_buffer (connection); if (MHD_NO == do_read (connection)) return MHD_YES; + MHD_update_last_activity_ (connection); while (1) { #if DEBUG_STATES @@ -2480,7 +2480,6 @@ MHD_connection_handle_write (struct MHD_Connection *connection) if (connection->suspended) return MHD_YES; - MHD_update_last_activity_ (connection); while (1) { #if DEBUG_STATES @@ -2529,6 +2528,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) &HTTP_100_CONTINUE[connection->continue_message_write_offset]); #endif connection->continue_message_write_offset += ret; + MHD_update_last_activity_ (connection); break; case MHD_CONNECTION_CONTINUE_SENT: case MHD_CONNECTION_BODY_RECEIVED: @@ -2537,7 +2537,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection) EXTRA_CHECK (0); break; case MHD_CONNECTION_HEADERS_SENDING: - do_write (connection); + if (MHD_NO != do_write (connection)) + MHD_update_last_activity_ (connection); if (MHD_CONNECTION_HEADERS_SENDING != connection->state) break; check_write_done (connection, @@ -2569,7 +2570,6 @@ MHD_connection_handle_write (struct MHD_Connection *connection) [(size_t)data_write_offset], response->data_size - (size_t)data_write_offset); - err = MHD_socket_get_error_ (); #if DEBUG_SEND_DATA if (ret > 0) fprintf (stderr, @@ -2583,6 +2583,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) MHD_mutex_unlock_chk_ (&response->mutex); if (ret < 0) { + err = MHD_socket_get_error_ (); if (MHD_SCKT_ERR_IS_EINTR_ (err) || MHD_SCKT_ERR_IS_EAGAIN_ (err)) return MHD_YES; @@ -2597,6 +2598,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) return MHD_YES; } connection->response_write_position += ret; + MHD_update_last_activity_ (connection); } if (connection->response_write_position == connection->response->total_size) @@ -2606,7 +2608,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection) EXTRA_CHECK (0); break; case MHD_CONNECTION_CHUNKED_BODY_READY: - do_write (connection); + if (MHD_NO != do_write (connection)) + MHD_update_last_activity_ (connection); if (MHD_CONNECTION_CHUNKED_BODY_READY != connection->state) break; check_write_done (connection, @@ -2620,7 +2623,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection) EXTRA_CHECK (0); break; case MHD_CONNECTION_FOOTERS_SENDING: - do_write (connection); + if (MHD_NO != do_write (connection)) + MHD_update_last_activity_ (connection); if (MHD_CONNECTION_FOOTERS_SENDING != connection->state) break; check_write_done (connection, diff --git a/src/microhttpd/connection_https.c b/src/microhttpd/connection_https.c @@ -48,7 +48,6 @@ run_tls_handshake (struct MHD_Connection *connection) { int ret; - MHD_update_last_activity_ (connection); if (MHD_TLS_CONNECTION_INIT == connection->state) { ret = gnutls_handshake (connection->tls_session); @@ -56,6 +55,7 @@ run_tls_handshake (struct MHD_Connection *connection) { /* set connection state to enable HTTP processing */ connection->state = MHD_CONNECTION_INIT; + MHD_update_last_activity_ (connection); return MHD_NO; } if ( (GNUTLS_E_AGAIN == ret) ||