[FFmpeg-devel] [PATCH 1/2] Introduce ff_network_wait_fd_timeout()

Michael Niedermayer michaelni at gmx.at
Tue Oct 9 01:48:33 CEST 2012


On Mon, Oct 08, 2012 at 10:39:41AM +0300, Andrey Utkin wrote:
> ---
>  libavformat/network.c |   22 ++++++++++++++++++++++
>  libavformat/network.h |   13 +++++++++++++
>  2 files changed, 35 insertions(+), 0 deletions(-)
> 
> diff --git a/libavformat/network.c b/libavformat/network.c
> index 0e79cae..3e142fc 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
> diff --git a/libavformat/network.h b/libavformat/network.h
> index cce188f..2c15427 100644
> --- a/libavformat/network.h
> +++ b/libavformat/network.h
> @@ -26,6 +26,7 @@
>  #include "config.h"
>  #include "libavutil/error.h"
>  #include "os_support.h"
> +#include "avio.h"
>  
>  #if HAVE_UNISTD_H
>  #include <unistd.h>
> @@ -80,6 +81,18 @@ void ff_tls_deinit(void);
>  
>  int ff_network_wait_fd(int fd, int write);
>  
> +/*
> + * This works similarly to ff_network_wait_fd, but waits up to 'timeout' microseconds

/** needed for doxy


> + * Uses ff_network_wait_fd in a loop
> + *
> + * @fd Socket descriptor
> + * @write Set 1 to wait for socket able to be read, 0 to be written
> + * @timeout Timeout interval, in microseconds. Actual precision is 100000 mcs, due to ff_network_wait_fd usage
> + * @param int_cb Interrupt callback, is checked after each ff_network_wait_fd call

> + * @return 0 if data can be read/written, AVERROR(EINVAL) if timeout expired, or negative error code

this mismatches the code which returns ETIMEDOUT


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

During times of universal deceit, telling the truth becomes a
revolutionary act. -- George Orwell
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121009/ef27f7bc/attachment.asc>


More information about the ffmpeg-devel mailing list