[vlc-devel] [PATCH 8/9] httpd: process client I/O before polling

RĂ©mi Denis-Courmont remi at remlab.net
Sat Jun 6 19:31:20 CEST 2020


In case of TLS, the TCP socket poll state does not necessarily match
the TLS stream state: data may be in the library-side TLS buffers.
So we need to try to read/write regardless of the socket events.

Refs #24824.
---
 src/network/httpd.c | 47 +++++++++++++++++----------------------------
 1 file changed, 18 insertions(+), 29 deletions(-)

diff --git a/src/network/httpd.c b/src/network/httpd.c
index ae19f81d78..6e1aed8a1b 100644
--- a/src/network/httpd.c
+++ b/src/network/httpd.c
@@ -1727,6 +1727,21 @@ static void httpdLoop(httpd_host_t *host)
 
     int canc = vlc_savecancel();
     vlc_list_foreach(cl, &host->clients, node) {
+        int val = -1;
+
+        switch (cl->i_state) {
+            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 (cl->i_state == HTTPD_CLIENT_DEAD
          || (cl->i_activity_timeout > 0
           && cl->i_activity_date + cl->i_activity_timeout < now)) {
@@ -1735,6 +1750,9 @@ static void httpdLoop(httpd_host_t *host)
             continue;
         }
 
+        if (val == 0)
+            cl->i_activity_date = now;
+
         struct pollfd *pufd = ufd + nfd;
         assert (pufd < ufd + ARRAY_SIZE (ufd));
 
@@ -1984,35 +2002,6 @@ static void httpdLoop(httpd_host_t *host)
     now = vlc_tick_now();
     nfd = host->nfd;
 
-    vlc_list_foreach(cl, &host->clients, node) {
-        const struct pollfd *pufd = &ufd[nfd];
-        int val = -1;
-
-        assert(pufd < &ufd[ARRAY_SIZE(ufd)]);
-
-        if (vlc_tls_GetFD(cl->sock) != pufd->fd)
-            continue; // we were not waiting for this client
-        ++nfd;
-        if (pufd->revents == 0)
-            continue; // no event received
-
-        switch (cl->i_state) {
-            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) */
     for (nfd = 0; nfd < host->nfd; nfd++) {
         int fd = ufd[nfd].fd;
-- 
2.27.0



More information about the vlc-devel mailing list