If set non-zero, limits duration of retry_transfer_wrapper() loop, thus
affects ffurl_read*(), ffurl_write()
Measured in microseconds.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -254,6 +254,7 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int |
254 | 254 |
{ |
255 | 255 |
int ret, len; |
256 | 256 |
int fast_retries = 5; |
257 |
+ int64_t wait_since = 0; |
|
257 | 258 |
|
258 | 259 |
len = 0; |
259 | 260 |
while (len < size_min) { |
... | ... |
@@ -264,10 +265,17 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int |
264 | 264 |
return ret; |
265 | 265 |
if (ret == AVERROR(EAGAIN)) { |
266 | 266 |
ret = 0; |
267 |
- if (fast_retries) |
|
267 |
+ if (fast_retries) { |
|
268 | 268 |
fast_retries--; |
269 |
- else |
|
269 |
+ } else { |
|
270 |
+ if (h->rw_timeout) { |
|
271 |
+ if (!wait_since) |
|
272 |
+ wait_since = av_gettime(); |
|
273 |
+ else if (av_gettime() > wait_since + h->rw_timeout) |
|
274 |
+ return AVERROR(ETIMEDOUT); |
|
275 |
+ } |
|
270 | 276 |
av_usleep(1000); |
277 |
+ } |
|
271 | 278 |
} else if (ret < 1) |
272 | 279 |
return ret < 0 ? ret : len; |
273 | 280 |
if (ret) |
... | ... |
@@ -48,6 +48,7 @@ typedef struct URLContext { |
48 | 48 |
int is_streamed; /**< true if streamed (no seek possible), default = false */ |
49 | 49 |
int is_connected; |
50 | 50 |
AVIOInterruptCB interrupt_callback; |
51 |
+ int64_t rw_timeout; /**< maximum time to wait for (network) read/write operation completion, in mcs */ |
|
51 | 52 |
} URLContext; |
52 | 53 |
|
53 | 54 |
typedef struct URLProtocol { |