diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-06-02 10:30:35 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-06-02 10:30:35 +0200 |
commit | 4d4f5911d3121133929da7b859755860f93684fd (patch) | |
tree | 25ca85b33909e89c0eb65b289158d14c79264af5 /libavformat/tcp.c | |
parent | 5711e4fd111a20afce15c90cb9b8d486f869a4e5 (diff) | |
parent | 28306e6d620c109ddd672f7243adfbc2bbb3b18f (diff) | |
download | ffmpeg-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>
Diffstat (limited to 'libavformat/tcp.c')
-rw-r--r-- | libavformat/tcp.c | 34 |
1 files changed, 7 insertions, 27 deletions
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: |