Commit 78707225 authored by Andrey Utkin's avatar Andrey Utkin Committed by Michael Niedermayer

Add 'rw_timeout' into URLContext

If set non-zero, limits duration of retry_transfer_wrapper() loop, thus
affects ffurl_read*(), ffurl_write()
Measured in microseconds.
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent a9b1a151
...@@ -254,6 +254,7 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int ...@@ -254,6 +254,7 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int
{ {
int ret, len; int ret, len;
int fast_retries = 5; int fast_retries = 5;
int64_t wait_since = 0;
len = 0; len = 0;
while (len < size_min) { while (len < size_min) {
...@@ -264,10 +265,17 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int ...@@ -264,10 +265,17 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int
return ret; return ret;
if (ret == AVERROR(EAGAIN)) { if (ret == AVERROR(EAGAIN)) {
ret = 0; ret = 0;
if (fast_retries) if (fast_retries) {
fast_retries--; fast_retries--;
else } else {
if (h->rw_timeout) {
if (!wait_since)
wait_since = av_gettime();
else if (av_gettime() > wait_since + h->rw_timeout)
return AVERROR(ETIMEDOUT);
}
av_usleep(1000); av_usleep(1000);
}
} else if (ret < 1) } else if (ret < 1)
return ret < 0 ? ret : len; return ret < 0 ? ret : len;
if (ret) if (ret)
......
...@@ -48,6 +48,7 @@ typedef struct URLContext { ...@@ -48,6 +48,7 @@ typedef struct URLContext {
int is_streamed; /**< true if streamed (no seek possible), default = false */ int is_streamed; /**< true if streamed (no seek possible), default = false */
int is_connected; int is_connected;
AVIOInterruptCB interrupt_callback; AVIOInterruptCB interrupt_callback;
int64_t rw_timeout; /**< maximum time to wait for (network) read/write operation completion, in mcs */
} URLContext; } URLContext;
typedef struct URLProtocol { typedef struct URLProtocol {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment