summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-06-02 10:30:35 +0200
committerMichael Niedermayer <michaelni@gmx.at>2013-06-02 10:30:35 +0200
commit4d4f5911d3121133929da7b859755860f93684fd (patch)
tree25ca85b33909e89c0eb65b289158d14c79264af5
parent5711e4fd111a20afce15c90cb9b8d486f869a4e5 (diff)
parent28306e6d620c109ddd672f7243adfbc2bbb3b18f (diff)
downloadffmpeg-4d4f5911d3121133929da7b859755860f93684fd.tar.gz
Merge commit '28306e6d620c109ddd672f7243adfbc2bbb3b18f'
* commit '28306e6d620c109ddd672f7243adfbc2bbb3b18f': network: factor out bind-listening code use my full first name instead of short one in copyrights Conflicts: libavformat/tcp.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavcodec/binkdata.h2
-rw-r--r--libavcodec/binkdsp.c2
-rw-r--r--libavcodec/binkdsp.h2
-rw-r--r--libavformat/network.c29
-rw-r--r--libavformat/network.h3
-rw-r--r--libavformat/rtmp.h2
-rw-r--r--libavformat/rtmppkt.c2
-rw-r--r--libavformat/rtmppkt.h2
-rw-r--r--libavformat/rtmpproto.c2
-rw-r--r--libavformat/tcp.c34
10 files changed, 46 insertions, 34 deletions
diff --git a/libavcodec/binkdata.h b/libavcodec/binkdata.h
index b9dc1f2639..57619beee2 100644
--- a/libavcodec/binkdata.h
+++ b/libavcodec/binkdata.h
@@ -1,6 +1,6 @@
/*
* Bink video decoder
- * Copyright (C) 2009 Kostya Shishkov
+ * Copyright (C) 2009 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
diff --git a/libavcodec/binkdsp.c b/libavcodec/binkdsp.c
index 2a9ef3dfe4..a23f9c73bd 100644
--- a/libavcodec/binkdsp.c
+++ b/libavcodec/binkdsp.c
@@ -1,6 +1,6 @@
/*
* Bink DSP routines
- * Copyright (c) 2009 Kostya Shishkov
+ * Copyright (c) 2009 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
diff --git a/libavcodec/binkdsp.h b/libavcodec/binkdsp.h
index 4968413bee..4c1f73f0c8 100644
--- a/libavcodec/binkdsp.h
+++ b/libavcodec/binkdsp.h
@@ -1,6 +1,6 @@
/*
* Bink DSP routines
- * Copyright (c) 2009 Kostya Shishkov
+ * Copyright (c) 2009 Konstantin Shishkov
*
* This file is part of Libav.
*
diff --git a/libavformat/network.c b/libavformat/network.c
index 766351eb6e..454ee13ff1 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -212,3 +212,32 @@ int ff_is_multicast_address(struct sockaddr *addr)
return 0;
}
+
+int ff_listen_bind(int fd, const struct sockaddr *addr,
+ socklen_t addrlen, int timeout)
+{
+ int ret;
+ int reuse = 1;
+ struct pollfd lp = { fd, POLLIN, 0 };
+ setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
+ ret = bind(fd, addr, addrlen);
+ if (ret)
+ return ff_neterrno();
+
+ ret = listen(fd, 1);
+ if (ret)
+ return ff_neterrno();
+
+ ret = poll(&lp, 1, timeout >= 0 ? timeout : -1);
+ if (ret <= 0)
+ return AVERROR(ETIMEDOUT);
+
+ ret = accept(fd, NULL, NULL);
+ if (ret < 0)
+ return ff_neterrno();
+
+ closesocket(fd);
+
+ ff_socket_nonblock(ret, 1);
+ return ret;
+}
diff --git a/libavformat/network.h b/libavformat/network.h
index f8b4dee50e..9335bbc0ad 100644
--- a/libavformat/network.h
+++ b/libavformat/network.h
@@ -222,4 +222,7 @@ const char *ff_gai_strerror(int ecode);
int ff_is_multicast_address(struct sockaddr *addr);
+int ff_listen_bind(int fd, const struct sockaddr *addr,
+ socklen_t addrlen, int timeout);
+
#endif /* AVFORMAT_NETWORK_H */
diff --git a/libavformat/rtmp.h b/libavformat/rtmp.h
index 7c9bb6d766..8fc8040d89 100644
--- a/libavformat/rtmp.h
+++ b/libavformat/rtmp.h
@@ -1,6 +1,6 @@
/*
* RTMP definitions
- * Copyright (c) 2009 Kostya Shishkov
+ * Copyright (c) 2009 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c
index c2015a5412..9800474c7e 100644
--- a/libavformat/rtmppkt.c
+++ b/libavformat/rtmppkt.c
@@ -1,6 +1,6 @@
/*
* RTMP input format
- * Copyright (c) 2009 Kostya Shishkov
+ * Copyright (c) 2009 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
diff --git a/libavformat/rtmppkt.h b/libavformat/rtmppkt.h
index a9422954f5..2740231c6d 100644
--- a/libavformat/rtmppkt.h
+++ b/libavformat/rtmppkt.h
@@ -1,6 +1,6 @@
/*
* RTMP packet utilities
- * Copyright (c) 2009 Kostya Shishkov
+ * Copyright (c) 2009 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 5164931ae3..0c473e578f 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -1,6 +1,6 @@
/*
* RTMP network protocol
- * Copyright (c) 2009 Kostya Shishkov
+ * Copyright (c) 2009 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 0d792e75b4..d06c18aa50 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -108,39 +108,18 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
cur_ai = ai;
restart:
- ret = AVERROR(EIO);
fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol);
- if (fd < 0)
+ if (fd < 0) {
+ ret = ff_neterrno();
goto fail;
+ }
if (s->listen) {
- int fd1;
- int reuse = 1;
- struct pollfd lp = { fd, POLLIN, 0 };
- setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
- ret = bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
- if (ret) {
- ret = ff_neterrno();
- goto fail1;
- }
- ret = listen(fd, 1);
- if (ret) {
- ret = ff_neterrno();
- goto fail1;
- }
- ret = poll(&lp, 1, s->listen_timeout >= 0 ? s->listen_timeout : -1);
- if (ret <= 0) {
- ret = AVERROR(ETIMEDOUT);
- goto fail1;
- }
- fd1 = accept(fd, NULL, NULL);
- if (fd1 < 0) {
- ret = ff_neterrno();
+ if ((fd = ff_listen_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
+ s->listen_timeout)) < 0) {
+ ret = fd;
goto fail1;
}
- closesocket(fd);
- fd = fd1;
- ff_socket_nonblock(fd, 1);
} else {
redo:
ff_socket_nonblock(fd, 1);
@@ -202,6 +181,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
cur_ai = cur_ai->ai_next;
if (fd >= 0)
closesocket(fd);
+ ret = 0;
goto restart;
}
fail1: