diff options
author | Andrey Utkin <andrey.krieger.utkin@gmail.com> | 2012-10-09 16:26:02 +0400 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-10-09 19:17:05 +0400 |
commit | d2b18c8f5b085d753bba315ce0d8d8da7c35e433 (patch) | |
tree | fe7dd54dc1316ceec7c0b40da8fe398516416da5 /libavformat/network.c | |
parent | 3a45688abc5c98c91fc6a1b0b8b68f0eca641aec (diff) |
Introduce ff_network_wait_fd_timeout()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/network.c')
-rw-r--r-- | libavformat/network.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/libavformat/network.c b/libavformat/network.c index 0e79cae7bf..3e142fceab 100644 --- a/libavformat/network.c +++ b/libavformat/network.c @@ -22,6 +22,8 @@ #include "network.h" #include "libavcodec/internal.h" #include "libavutil/mem.h" +#include "url.h" +#include "libavutil/time.h" #define THREADS (HAVE_PTHREADS || (defined(WIN32) && !defined(__MINGW32CE__))) @@ -150,6 +152,26 @@ int ff_network_wait_fd(int fd, int write) return ret < 0 ? ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 : AVERROR(EAGAIN); } +int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, AVIOInterruptCB *int_cb) +{ + int ret; + int64_t wait_start = 0; + + while (1) { + ret = ff_network_wait_fd(fd, write); + if (ret != AVERROR(EAGAIN)) + return ret; + if (ff_check_interrupt(int_cb)) + return AVERROR_EXIT; + if (timeout) { + if (!wait_start) + wait_start = av_gettime(); + else if (av_gettime() - wait_start > timeout) + return AVERROR(ETIMEDOUT); + } + } +} + void ff_network_close(void) { #if HAVE_WINSOCK2_H |