Parcourir la source

Do not update last activity time on connections without timeout timer

Evgeny Grin (Karlson2k) il y a 9 ans
Parent
commit
396aab2e11
3 fichiers modifiés avec 12 ajouts et 3 suppressions
  1. 2 0
      src/include/microhttpd.h
  2. 9 2
      src/microhttpd/connection.c
  3. 1 1
      src/microhttpd/connection.h

+ 2 - 0
src/include/microhttpd.h

@@ -3143,6 +3143,8 @@ enum MHD_CONNECTION_OPTION
    * Set a custom timeout for the given connection.  Specified
    * as the number of seconds, given as an `unsigned int`.  Use
    * zero for no timeout.
+   * If timeout was set to zero (or unset) before, setup of new value by
+   * MHD_set_connection_option() will reset timeout timer.
    */
   MHD_CONNECTION_OPTION_TIMEOUT
 

+ 9 - 2
src/microhttpd/connection.c

@@ -2373,11 +2373,15 @@ MHD_update_last_activity_ (struct MHD_Connection *connection)
 {
   struct MHD_Daemon *daemon = connection->daemon;
 
+  if (0 == connection->connection_timeout)
+    return; /* Skip update of activity for connections
+               without timeout timer. */
+  if (connection->suspended)
+    return; /* no activity on suspended connections */
+
   connection->last_activity = MHD_monotonic_sec_counter();
   if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
     return; /* each connection has personal timeout */
-  if (connection->suspended)
-    return; /* not timeouts for suspended connections */
 
   if (connection->connection_timeout != daemon->connection_timeout)
     return; /* custom timeout, no need to move it in "normal" DLL */
@@ -3373,6 +3377,9 @@ MHD_set_connection_option (struct MHD_Connection *connection,
   switch (option)
     {
     case MHD_CONNECTION_OPTION_TIMEOUT:
+      if (0 == connection->connection_timeout)
+        connection->last_activity = MHD_monotonic_sec_counter();
+
       MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
       if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
           (! connection->suspended) )

+ 1 - 1
src/microhttpd/connection.h

@@ -142,6 +142,6 @@ MHD_connection_epoll_update_ (struct MHD_Connection *connection);
  * @param connection the connection that saw some activity
  */
 void
-update_last_activity (struct MHD_Connection *connection);
+MHD_update_last_activity_ (struct MHD_Connection *connection);
 
 #endif