[FFmpeg-devel] [PATCH 1/6] tcp: use timeout option consistently

Michael Niedermayer michaelni at gmx.at
Thu Sep 13 20:49:44 CEST 2012


On Thu, Sep 13, 2012 at 03:43:28AM +0300, Andrey Utkin wrote:
> Default _connection_ timeout value 5 seconds is left as i/o timeout also
> ---
>  libavformat/tcp.c |   41 +++++++++++++++++++++++++++++++----------
>  1 files changed, 31 insertions(+), 10 deletions(-)
> 
> diff --git a/libavformat/tcp.c b/libavformat/tcp.c
> index 8cd217b..d3487b7 100644
> --- a/libavformat/tcp.c
> +++ b/libavformat/tcp.c
> @@ -43,9 +43,10 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
>      char buf[256];
>      int ret;
>      socklen_t optlen;
> -    int timeout = 50, listen_timeout = -1;
> +    int listen_timeout = -1;
>      char hostname[1024],proto[1024],path[1024];
>      char portstr[10];
> +    h->rw_timeout = 5000000;
>  
>      av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname),
>          &port, path, sizeof(path), uri);
> @@ -60,7 +61,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
>          if (av_find_info_tag(buf, sizeof(buf), "listen", p))
>              listen_socket = 1;
>          if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) {
> -            timeout = strtol(buf, NULL, 10);
> +            h->rw_timeout = strtol(buf, NULL, 10);
>          }
>          if (av_find_info_tag(buf, sizeof(buf), "listen_timeout", p)) {
>              listen_timeout = strtol(buf, NULL, 10);
> @@ -126,6 +127,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
>  
>      if (ret < 0) {
>          struct pollfd p = {fd, POLLOUT, 0};
> +        int64_t wait_started;
>          ret = ff_neterrno();
>          if (ret == AVERROR(EINTR)) {
>              if (ff_check_interrupt(&h->interrupt_callback)) {
> @@ -139,7 +141,8 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
>              goto fail;
>  
>          /* wait until we are connected or until abort */
> -        while(timeout--) {
> +        wait_started = av_gettime();
> +        do {
>              if (ff_check_interrupt(&h->interrupt_callback)) {
>                  ret = AVERROR_EXIT;
>                  goto fail1;
> @@ -147,7 +150,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
>              ret = poll(&p, 1, 100);
>              if (ret > 0)
>                  break;
> -        }
> +        } while (!h->rw_timeout || (av_gettime() - wait_started < h->rw_timeout));
>          if (ret <= 0) {
>              ret = AVERROR(ETIMEDOUT);
>              goto fail;

> @@ -192,9 +195,18 @@ static int tcp_read(URLContext *h, uint8_t *buf, int size)
>      int ret;
>  
>      if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
> -        ret = ff_network_wait_fd(s->fd, 0);
> -        if (ret < 0)
> -            return ret;

> +        int64_t wait_start = av_gettime();

this is problematic
ive tested and my box doesnt manage 1 million such calls per second
rather slightly less so if we would assume TCP packets of 1kb
then at 1gbit/sec 10% of the time would be spend in av_gettime()
and 10gbit/sec would not be possible at all


[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Frequently ignored awnser#1 FFmpeg bugs should be sent to our bugtracker. User
questions about the command line tools should be sent to the ffmpeg-user ML.
And questions about how to use libav* should be sent to the libav-user ML.
-------------- 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/20120913/23d40235/attachment.asc>


More information about the ffmpeg-devel mailing list