0015-io-implement-network-timeout-default-60s.patch 1.85 KB
Newer Older
1
From 9ccf37b1a093e2460633f69ce484d2fd31ccdc8c Mon Sep 17 00:00:00 2001
2
From: Gleb Pinigin <gpinigin@gmail.com>
3
Date: Sun, 28 Jul 2013 18:32:51 +0700
4
Subject: [PATCH 15/17] io: implement network timeout(default 60s)
5 6

---
7 8
 src/network/io.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
9 10

diff --git a/src/network/io.c b/src/network/io.c
11
index a8ea870..6df06e1 100644
12 13 14 15 16 17 18 19 20 21
--- a/src/network/io.c
+++ b/src/network/io.c
@@ -33,6 +33,7 @@
 #endif
 
 #include <vlc_common.h>
+#include <vlc_access.h>
 
 #include <stdlib.h>
 #include <stdio.h>
22
@@ -73,6 +74,9 @@
23 24 25 26 27 28 29 30 31
 # define SOL_DCCP 269
 #endif
 
+#define MAX_TIMEOUT 60000
+#define POLL_TIMEOUT 10000
+
 #include "libvlc.h" /* vlc_object_waitpipe */
 
 extern int rootwrap_bind (int family, int socktype, int protocol,
32
@@ -267,6 +271,7 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
33 34
     ufd[1].fd = vlc_object_waitpipe (p_this);
     ufd[1].events = POLLIN;
35 36
 
+    int i_timepassed = 0;
37 38
     size_t i_total = 0;
     do
39
     {
40
@@ -288,6 +293,13 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
41
 
42 43 44 45 46 47 48 49 50 51 52 53 54
         if (n < 0)
         {
+            if (i_timepassed >= MAX_TIMEOUT && i_total == 0)
+            {
+                access_t *p_access = (access_t *)p_this;
+                p_access->info.b_eof = true;
+                goto error;
+            }
+
             switch (net_errno)
             {
                 case EAGAIN: /* no data */
@@ -326,8 +338,9 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
55 56 57 58
             return -1;
         }
 
+        i_timepassed += POLL_TIMEOUT;
59 60 61
         /* Wait for more data */
-        if (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), -1) < 0)
+        if (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), POLL_TIMEOUT) < 0)
62
         {
63 64
             if (errno == EINTR)
                 continue;
65
-- 
66
1.8.3.4 (Apple Git-47)
67