httpd: update activity time on actual activity
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 6 Jun 2020 17:04:16 +0000 (20:04 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Mon, 8 Jun 2020 13:50:39 +0000 (16:50 +0300)
Account for actual data read or written, rather than iteration of the
poll loop.

Note: This won't count TLS handshake progress as activity. But if
the client cannot complete the handshake within a time-out interval,
we might as well drop it.

src/network/httpd.c

index d36c631..ae19f81 100644 (file)
@@ -1986,6 +1986,7 @@ static void httpdLoop(httpd_host_t *host)
 
     vlc_list_foreach(cl, &host->clients, node) {
         const struct pollfd *pufd = &ufd[nfd];
+        int val = -1;
 
         assert(pufd < &ufd[ARRAY_SIZE(ufd)]);
 
@@ -1995,16 +1996,21 @@ static void httpdLoop(httpd_host_t *host)
         if (pufd->revents == 0)
             continue; // no event received
 
-        cl->i_activity_date = now;
-
         switch (cl->i_state) {
-            case HTTPD_CLIENT_RECEIVING: httpd_ClientRecv(cl); break;
-            case HTTPD_CLIENT_SENDING:   httpd_ClientSend(cl); break;
+            case HTTPD_CLIENT_RECEIVING:
+                val = httpd_ClientRecv(cl);
+                break;
+            case HTTPD_CLIENT_SENDING:
+                val = httpd_ClientSend(cl);
+                break;
             case HTTPD_CLIENT_TLS_HS_IN:
             case HTTPD_CLIENT_TLS_HS_OUT:
                 httpd_ClientTlsHandshake(host, cl);
                 break;
         }
+
+        if (val == 0)
+            cl->i_activity_date = now;
     }
 
     /* Handle server sockets (accept new connections) */