Răsfoiți Sursa

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

Evgeny Grin (Karlson2k) 9 ani în urmă
părinte
comite
76500135fe
3 a modificat fișierele cu 15 adăugiri și 7 ștergeri
  1. 4 0
      ChangeLog
  2. 10 6
      src/microhttpd/connection.c
  3. 1 1
      src/microhttpd/connection_https.c

+ 4 - 0
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
 

+ 10 - 6
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,

+ 1 - 1
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) ||