[vlc-devel] [PATCH 4/9] httpd: don't bother processing failed connection

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


If the underlying stream failed, there's no point processing an
outstanding request. It's most likely incomplete, and in any case, we
won't be able to send the response.

That corner case only made sense for connections half-closed on read
end. (Even then, it's a little questionable, because half-closed
connections eventually time out if not fully closed.)
---
 src/network/httpd.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/network/httpd.c b/src/network/httpd.c
index 1935487c50..2eece86430 100644
--- a/src/network/httpd.c
+++ b/src/network/httpd.c
@@ -1540,13 +1540,7 @@ static void httpd_ClientRecv(httpd_client_t *cl)
         }
     }
 
-    /* check if the client is to be set to dead */
-#if defined(_WIN32)
-    if ((i_len < 0 && WSAGetLastError() != WSAEWOULDBLOCK) || (i_len == 0))
-#else
-    if ((i_len < 0 && errno != EAGAIN) || (i_len == 0))
-#endif
-    {
+    if (i_len == 0) {
         if (cl->query.i_proto != HTTPD_PROTO_NONE && cl->query.i_type != HTTPD_MSG_NONE) {
             /* connection closed -> end of data */
             if (cl->query.i_body > 0)
@@ -1554,7 +1548,19 @@ static void httpd_ClientRecv(httpd_client_t *cl)
             cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
         }
         else
-            cl->i_state = HTTPD_CLIENT_DEAD;
+            cl->i_state = HTTPD_CLIENT_DEAD; /* connection failed */
+        return;
+    }
+
+    /* check if the client is to be set to dead */
+    if (i_len < 0) {
+#if defined(_WIN32)
+        if (WSAGetLastError() != WSAEWOULDBLOCK)
+#else
+        if (errno != EAGAIN)
+#endif
+            cl->i_state = HTTPD_CLIENT_DEAD; /* connection failed */
+        return;
     }
 
     /* XXX: for QT I have to disable timeout. Try to find why */
-- 
2.27.0



More information about the vlc-devel mailing list