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/network.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/network.c')
-rw-r--r-- | libavformat/network.c | 29 |
1 files changed, 29 insertions, 0 deletions
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; +} |