]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/tcp.c
Partial rewrite stream probe code.
[ffmpeg] / libavformat / tcp.c
index 29eb60abe9e45be1d0fa0f8a0ed8e01e4888c752..fb94b639844e73214f626154785ed1e71eb32342 100644 (file)
@@ -71,25 +71,34 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
  redo:
     ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
     if (ret < 0) {
+        int timeout=50;
         struct pollfd p = {fd, POLLOUT, 0};
-        if (ff_neterrno() == FF_NETERROR(EINTR)) {
-            if (url_interrupt_cb())
+        if (ff_neterrno() == AVERROR(EINTR)) {
+            if (url_interrupt_cb()) {
+                ret = AVERROR_EXIT;
                 goto fail1;
+            }
             goto redo;
         }
-        if (ff_neterrno() != FF_NETERROR(EINPROGRESS) &&
-            ff_neterrno() != FF_NETERROR(EAGAIN))
+        if (ff_neterrno() != AVERROR(EINPROGRESS) &&
+            ff_neterrno() != AVERROR(EAGAIN))
             goto fail;
 
         /* wait until we are connected or until abort */
         for(;;) {
             if (url_interrupt_cb()) {
-                ret = AVERROR(EINTR);
+                ret = AVERROR_EXIT;
                 goto fail1;
             }
             ret = poll(&p, 1, 100);
             if (ret > 0)
                 break;
+            if(!--timeout){
+                av_log(NULL, AV_LOG_ERROR,
+                    "TCP open %s:%d timeout\n",
+                    hostname, port);
+                goto fail;
+            }
         }
 
         /* test error */
@@ -136,7 +145,7 @@ static int tcp_wait_fd(int fd, int write)
     int ret;
 
     ret = poll(&p, 1, 100);
-    return ret < 0 ? ff_neterrno() : p.revents & ev ? 0 : FF_NETERROR(EAGAIN);
+    return ret < 0 ? ff_neterrno() : p.revents & ev ? 0 : AVERROR(EAGAIN);
 }
 
 static int tcp_read(URLContext *h, uint8_t *buf, int size)