aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/network.c
diff options
context:
space:
mode:
authorStephan Holljes <klaxa1337@googlemail.com>2015-07-03 02:22:25 +0200
committerStephan Holljes <klaxa1337@googlemail.com>2015-08-01 00:58:31 +0200
commitcf6c871beec9039dc6d7ebda57358161d64062c3 (patch)
tree5087a55abc6b9c67d9481e3969b1439793d9d6f8 /libavformat/network.c
parent5870b3d2a3afdae0ed42fa9fd010684ee18feca8 (diff)
downloadffmpeg-cf6c871beec9039dc6d7ebda57358161d64062c3.tar.gz
lavf/network: split ff_listen_bind into ff_listen and ff_accept
Signed-off-by: Stephan Holljes <klaxa1337@googlemail.com>
Diffstat (limited to 'libavformat/network.c')
-rw-r--r--libavformat/network.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/libavformat/network.c b/libavformat/network.c
index 47ade8cb62..7a326d2c4e 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -187,12 +187,11 @@ int ff_socket(int af, int type, int proto)
return fd;
}
-int ff_listen_bind(int fd, const struct sockaddr *addr,
- socklen_t addrlen, int timeout, URLContext *h)
+int ff_listen(int fd, const struct sockaddr *addr,
+ socklen_t addrlen)
{
int ret;
int reuse = 1;
- struct pollfd lp = { fd, POLLIN, 0 };
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse))) {
av_log(NULL, AV_LOG_WARNING, "setsockopt(SO_REUSEADDR) failed\n");
}
@@ -203,6 +202,13 @@ int ff_listen_bind(int fd, const struct sockaddr *addr,
ret = listen(fd, 1);
if (ret)
return ff_neterrno();
+ return ret;
+}
+
+int ff_accept(int fd, int timeout, URLContext *h)
+{
+ int ret;
+ struct pollfd lp = { fd, POLLIN, 0 };
ret = ff_poll_interrupt(&lp, 1, timeout, &h->interrupt_callback);
if (ret < 0)
@@ -211,15 +217,24 @@ int ff_listen_bind(int fd, const struct sockaddr *addr,
ret = accept(fd, NULL, NULL);
if (ret < 0)
return ff_neterrno();
-
- closesocket(fd);
-
if (ff_socket_nonblock(ret, 1) < 0)
av_log(NULL, AV_LOG_DEBUG, "ff_socket_nonblock failed\n");
return ret;
}
+int ff_listen_bind(int fd, const struct sockaddr *addr,
+ socklen_t addrlen, int timeout, URLContext *h)
+{
+ int ret;
+ if ((ret = ff_listen(fd, addr, addrlen)) < 0)
+ return ret;
+ if ((ret = ff_accept(fd, timeout, h)) < 0)
+ return ret;
+ closesocket(fd);
+ return ret;
+}
+
int ff_listen_connect(int fd, const struct sockaddr *addr,
socklen_t addrlen, int timeout, URLContext *h,
int will_try_next)