diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-07-06 01:33:19 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-07-06 01:33:19 +0200 |
commit | 68b7b534be5912dbd28283d0d566a2ee88e51f9b (patch) | |
tree | ae50fa52befb15d5f179214bc746f70171bfeabe /libavformat/tcp.c | |
parent | efa9e6b4234534682bf7e4629c2e8024e35c64f2 (diff) | |
download | ffmpeg-68b7b534be5912dbd28283d0d566a2ee88e51f9b.tar.gz |
tcp: Use a default timeout of 5 sec for opening a connection but not for receiving packets
This should be closer to how tcp behaved longer ago and should
fix the issue with idle connections timing out.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/tcp.c')
-rw-r--r-- | libavformat/tcp.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/libavformat/tcp.c b/libavformat/tcp.c index 61b7d688a5..bf51701437 100644 --- a/libavformat/tcp.c +++ b/libavformat/tcp.c @@ -34,6 +34,7 @@ typedef struct TCPContext { const AVClass *class; int fd; int listen; + int open_timeout; int rw_timeout; int listen_timeout; } TCPContext; @@ -43,7 +44,7 @@ typedef struct TCPContext { #define E AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { {"listen", "listen on port instead of connecting", OFFSET(listen), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, D|E }, -{"timeout", "timeout of socket i/o operations", OFFSET(rw_timeout), AV_OPT_TYPE_INT, {.i64 = 5000000}, 0, INT_MAX, D|E }, +{"timeout", "timeout of socket i/o operations", OFFSET(rw_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, D|E }, {"listen_timeout", "connection awaiting timeout", OFFSET(listen_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, D|E }, {NULL} }; @@ -66,6 +67,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags) int ret; char hostname[1024],proto[1024],path[1024]; char portstr[10]; + s->open_timeout = 5000000; av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port, path, sizeof(path), uri); @@ -86,7 +88,10 @@ static int tcp_open(URLContext *h, const char *uri, int flags) s->listen_timeout = strtol(buf, NULL, 10); } } - h->rw_timeout = s->rw_timeout; + if (s->rw_timeout >= 0) { + s->open_timeout = + h->rw_timeout = s->rw_timeout; + } hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; snprintf(portstr, sizeof(portstr), "%d", port); @@ -120,7 +125,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags) } } else { if ((ret = ff_listen_connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen, - h->rw_timeout / 1000, h)) < 0) { + s->open_timeout / 1000, h)) < 0) { if (ret == AVERROR_EXIT) goto fail1; |