]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/tcp.c
rename idroq.c to idroqdec.c
[ffmpeg] / libavformat / tcp.c
index a8cf80fbffd09d28208e6627f9709381fbe0b93b..ca4a6b0b25e2cc67e8f65756314604cbd0e633fd 100644 (file)
@@ -20,6 +20,7 @@
  */
 #include "avformat.h"
 #include <unistd.h>
+#include "internal.h"
 #include "network.h"
 #include "os_support.h"
 #if HAVE_SYS_SELECT_H
@@ -44,10 +45,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
     char hostname[1024],proto[1024],path[1024];
     char portstr[10];
 
-    if(!ff_network_init())
-        return AVERROR(EIO);
-
-    url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname),
+    av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname),
         &port, path, sizeof(path), uri);
     if (strcmp(proto,"tcp") || port <= 0 || port >= 65536)
         return AVERROR(EINVAL);
@@ -56,8 +54,13 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
     hints.ai_family = AF_UNSPEC;
     hints.ai_socktype = SOCK_STREAM;
     snprintf(portstr, sizeof(portstr), "%d", port);
-    if (getaddrinfo(hostname, portstr, &hints, &ai))
+    ret = getaddrinfo(hostname, portstr, &hints, &ai);
+    if (ret) {
+        av_log(NULL, AV_LOG_ERROR,
+               "Failed to resolve hostname %s: %s\n",
+               hostname, gai_strerror(ret));
         return AVERROR(EIO);
+    }
 
     cur_ai = ai;
 
@@ -95,8 +98,12 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
         /* test error */
         optlen = sizeof(ret);
         getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen);
-        if (ret != 0)
+        if (ret != 0) {
+            av_log(NULL, AV_LOG_ERROR,
+                   "TCP connection to %s:%d failed: %s\n",
+                   hostname, port, strerror(ret));
             goto fail;
+        }
     }
     s = av_malloc(sizeof(TCPContext));
     if (!s) {
@@ -149,12 +156,14 @@ static int tcp_read(URLContext *h, uint8_t *buf, int size)
                     return AVERROR(ff_neterrno());
             } else return len;
         } else if (ret < 0) {
+            if (ff_neterrno() == FF_NETERROR(EINTR))
+                continue;
             return -1;
         }
     }
 }
 
-static int tcp_write(URLContext *h, uint8_t *buf, int size)
+static int tcp_write(URLContext *h, const uint8_t *buf, int size)
 {
     TCPContext *s = h->priv_data;
     int ret, size1, fd_max, len;
@@ -182,6 +191,8 @@ static int tcp_write(URLContext *h, uint8_t *buf, int size)
             size -= len;
             buf += len;
         } else if (ret < 0) {
+            if (ff_neterrno() == FF_NETERROR(EINTR))
+                continue;
             return -1;
         }
     }
@@ -192,7 +203,6 @@ static int tcp_close(URLContext *h)
 {
     TCPContext *s = h->priv_data;
     closesocket(s->fd);
-    ff_network_close();
     av_free(s);
     return 0;
 }