[vlc-commits] network: fix net_Connect() time-out

Rémi Denis-Courmont git at videolan.org
Sun Nov 5 16:40:43 CET 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Nov  5 17:39:45 2017 +0200| [93b6b5a086836274a1d35199ef31a238fc55a11d] | committer: Rémi Denis-Courmont

network: fix net_Connect() time-out

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

 src/network/tcp.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/network/tcp.c b/src/network/tcp.c
index 3a4f397541..bc2a116532 100644
--- a/src/network/tcp.c
+++ b/src/network/tcp.c
@@ -34,6 +34,7 @@
 
 #include <errno.h>
 #include <assert.h>
+#include <limits.h>
 #include <unistd.h>
 #ifdef HAVE_POLL
 # include <poll.h>
@@ -137,9 +138,8 @@ int net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
     }
     free( psz_socks );
 
-    int timeout = var_InheritInteger (p_this, "ipv4-timeout");
-    if (timeout < 0)
-        timeout = -1;
+    mtime_t timeout = var_InheritInteger(p_this, "ipv4-timeout")
+                      * (CLOCK_FREQ / 1000);
 
     for (struct addrinfo *ptr = res; ptr != NULL; ptr = ptr->ai_next)
     {
@@ -161,16 +161,28 @@ int net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
             }
 
             struct pollfd ufd;
+            mtime_t deadline = VLC_TS_INVALID;
 
             ufd.fd = fd;
             ufd.events = POLLOUT;
+            if (timeout > 0)
+                deadline = mdate() + timeout;
 
-            do  /* NOTE: timeout screwed up if we catch a signal (EINTR) */
+            do
             {
+                int ms = -1;
+
                 if (vlc_killed())
                     goto next_ai;
 
-                val = vlc_poll_i11e(&ufd, 1, timeout);
+                if (deadline != VLC_TS_INVALID)
+                {
+                    ms = (deadline - mdate()) / (CLOCK_FREQ / 1000);
+                    if (ms > INT_MAX)
+                        ms = INT_MAX;
+                }
+
+                val = vlc_poll_i11e(&ufd, 1, ms);
             }
             while (val == -1 && errno == EINTR);
 



More information about the vlc-commits mailing list