| 502 | |
| 503 | |
| 504 | static inline int retry_transfer_wrapper(URLContext *h, uint8_t *buf, |
| 505 | const uint8_t *cbuf, |
| 506 | int size, int size_min, |
| 507 | int read) |
| 508 | { |
| 509 | int ret, len; |
| 510 | int fast_retries = 5; |
| 511 | int64_t wait_since = 0; |
| 512 | |
| 513 | len = 0; |
| 514 | while (len < size_min) { |
| 515 | if (ff_check_interrupt(&h->interrupt_callback)) |
| 516 | return AVERROR_EXIT; |
| 517 | ret = read ? h->prot->url_read (h, buf + len, size - len): |
| 518 | h->prot->url_write(h, cbuf + len, size - len); |
| 519 | if (ret == AVERROR(EINTR)) |
| 520 | continue; |
| 521 | if (h->flags & AVIO_FLAG_NONBLOCK) |
| 522 | return ret; |
| 523 | if (ret == AVERROR(EAGAIN)) { |
| 524 | ret = 0; |
| 525 | if (fast_retries) { |
| 526 | fast_retries--; |
| 527 | } else { |
| 528 | if (h->rw_timeout) { |
| 529 | if (!wait_since) |
| 530 | wait_since = av_gettime_relative(); |
| 531 | else if (av_gettime_relative() > wait_since + h->rw_timeout) |
| 532 | return AVERROR(EIO); |
| 533 | } |
| 534 | av_usleep(1000); |
| 535 | } |
| 536 | } else if (ret == AVERROR_EOF) |
| 537 | return (len > 0) ? len : AVERROR_EOF; |
| 538 | else if (ret < 0) |
| 539 | return ret; |
| 540 | if (ret) { |
| 541 | fast_retries = FFMAX(fast_retries, 2); |
| 542 | wait_since = 0; |
| 543 | } |
| 544 | len += ret; |
| 545 | } |
| 546 | return len; |
| 547 | } |
| 548 | |
| 549 | int ffurl_read2(void *urlcontext, uint8_t *buf, int size) |
| 550 | { |
no test coverage detected