[vlc-commits] net_Recv(): improve error handling (fixes #9081)

Rémi Denis-Courmont git at videolan.org
Tue Jul 30 17:09:11 CEST 2013


vlc/vlc-2.1 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Jul 30 18:07:14 2013 +0300| [6f9920ffc3e4ae810c9ecd11ff78eb9368db1aeb] | committer: Rémi Denis-Courmont

net_Recv(): improve error handling (fixes #9081)

(cherry picked from commit e8f36f6e7f54b8bcf6d5341af1cdc626c2b6c800)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.1.git/?a=commit;h=6f9920ffc3e4ae810c9ecd11ff78eb9368db1aeb
---

 src/network/io.c |   29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/src/network/io.c b/src/network/io.c
index 9b13b2a..21bf82b 100644
--- a/src/network/io.c
+++ b/src/network/io.c
@@ -61,6 +61,10 @@
 #if defined(_WIN32)
 # undef EAFNOSUPPORT
 # define EAFNOSUPPORT WSAEAFNOSUPPORT
+# undef EWOULDBLOCK
+# define EWOULDBLOCK WSAEWOULDBLOCK
+# undef EAGAIN
+# define EAGAIN WSAEWOULDBLOCK
 #endif
 
 #ifdef HAVE_LINUX_DCCP_H
@@ -286,13 +290,15 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
         {
             switch (net_errno)
             {
-                case EAGAIN: /* spurious wakeup or no TLS data */
+                case EAGAIN: /* no data */
 #if (EAGAIN != EWOULDBLOCK)
                 case EWOULDBLOCK:
 #endif
-                case EINTR:  /* asynchronous signal */
                     break;
-#ifdef _WIN32
+#ifndef _WIN32
+                case EINTR:  /* asynchronous signal */
+                    continue;
+#else
                 case WSAEMSGSIZE: /* datagram too big */
                     n = i_buflen;
                     break;
@@ -311,25 +317,26 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
             if (!waitall)
                 break;
         }
-        else
+        else /* n == 0 */
             break;/* end of stream or empty packet */
 
-        /* Wait for more data */
         if (ufd[1].fd == -1)
         {
             errno = EINTR;
             return -1;
         }
-        while (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), -1) < 0)
-            if (errno != EINTR)
-                goto error;
+
+        /* Wait for more data */
+        if (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), -1) < 0)
+        {
+            if (errno == EINTR)
+                continue;
+            goto error;
+        }
 
         if (ufd[1].revents)
         {
             msg_Dbg (p_this, "socket %d polling interrupted", fd);
-#if defined(_WIN32)
-            WSASetLastError (WSAEINTR);
-#endif
             errno = EINTR;
             return -1;
         }



More information about the vlc-commits mailing list