[vlc-commits] net_Read(): truly ignore POLLRDHUP

Rémi Denis-Courmont git at videolan.org
Wed Apr 18 15:40:14 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Apr 18 16:35:12 2012 +0300| [546cdb234c30d12b4dffbcddf16d9c150091ff28] | committer: Rémi Denis-Courmont

net_Read(): truly ignore POLLRDHUP

The Linux TCP stack sets POLLRDHUP as soon as the FIN packet is
received. If there is some unread data in the receive buffer, it would
be discarded. Then upper layer protocol typically fail.

This can happen with HTTP/1.1 "Connection: close" or with HTTP/1.0
in particular.

Pointed-out-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=546cdb234c30d12b4dffbcddf16d9c150091ff28
---

 src/network/io.c |    9 ++-------
 1 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/src/network/io.c b/src/network/io.c
index 25dbbfe..1fc8361 100644
--- a/src/network/io.c
+++ b/src/network/io.c
@@ -257,12 +257,9 @@ ssize_t
 net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
           void *restrict p_buf, size_t i_buflen, bool waitall)
 {
-#ifndef POLLRDHUP /* This is nice but non-portable */
-# define POLLRDHUP 0
-#endif
     size_t i_total = 0;
     struct pollfd ufd[2] = {
-        { .fd = fd,                           .events = POLLIN|POLLRDHUP },
+        { .fd = fd,                           .events = POLLIN },
         { .fd = vlc_object_waitpipe (p_this), .events = POLLIN },
     };
 
@@ -271,8 +268,6 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
 
     while (i_buflen > 0)
     {
-        ufd[0].revents = ufd[1].revents = 0;
-
         if (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), -1) < 0)
         {
             if (errno != EINTR)
@@ -285,7 +280,7 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
             /* Errors (-1) and EOF (0) will be returned on next call,
              * otherwise we'd "hide" the error from the caller, which is a
              * bad idea™. */
-            if (ufd[0].revents & (POLLERR|POLLNVAL|POLLRDHUP))
+            if (ufd[0].revents & (POLLERR|POLLNVAL))
                 break;
             if (ufd[1].revents)
                 break;



More information about the vlc-commits mailing list