]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/network.c
Add support for BDAV/m2ts-mode muxing
[ffmpeg] / libavformat / network.c
index d8e6540b19d4bde39db6b08e3fc47a11982c3cb8..6d308ebd012e2eee57ccd2786bdf09db6bdc2053 100644 (file)
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <fcntl.h>
 #include "network.h"
 #include "url.h"
 #include "libavcodec/internal.h"
@@ -210,6 +211,24 @@ static int ff_poll_interrupt(struct pollfd *p, nfds_t nfds, int timeout,
     return ret;
 }
 
+int ff_socket(int af, int type, int proto)
+{
+    int fd;
+
+#ifdef SOCK_CLOEXEC
+    fd = socket(af, type | SOCK_CLOEXEC, proto);
+    if (fd == -1 && errno == EINVAL)
+#endif
+    {
+        fd = socket(af, type, proto);
+#if HAVE_FCNTL
+        if (fd != -1)
+            fcntl(fd, F_SETFD, FD_CLOEXEC);
+#endif
+    }
+    return fd;
+}
+
 int ff_listen_bind(int fd, const struct sockaddr *addr,
                    socklen_t addrlen, int timeout, URLContext *h)
 {
@@ -240,7 +259,8 @@ int ff_listen_bind(int fd, const struct sockaddr *addr,
 }
 
 int ff_listen_connect(int fd, const struct sockaddr *addr,
-                      socklen_t addrlen, int timeout, URLContext *h)
+                      socklen_t addrlen, int timeout, URLContext *h,
+                      int will_try_next)
 {
     struct pollfd p = {fd, POLLOUT, 0};
     int ret;
@@ -267,9 +287,13 @@ int ff_listen_connect(int fd, const struct sockaddr *addr,
                 char errbuf[100];
                 ret = AVERROR(ret);
                 av_strerror(ret, errbuf, sizeof(errbuf));
-                av_log(h, AV_LOG_ERROR,
-                       "Connection to %s failed: %s\n",
-                       h->filename, errbuf);
+                if (will_try_next)
+                    av_log(h, AV_LOG_WARNING,
+                           "Connection to %s failed (%s), trying next address\n",
+                           h->filename, errbuf);
+                else
+                    av_log(h, AV_LOG_ERROR, "Connection to %s failed: %s\n",
+                           h->filename, errbuf);
             }
         default:
             return ret;