Skip to content

Commit

Permalink
transfer.c: break receive loop in speed limited transfers
Browse files Browse the repository at this point in the history
- the change breaks looping in transfer.c receive for transfers that are
  speed limited on having gotten *some* bytes.
- the overall speed limit timing is done in multi.c

Reported-by: Dmitry Karpov
Bug: https://curl.se/mail/lib-2024-03/0001.html
Closes curl#13050
  • Loading branch information
icing authored and bagder committed Mar 6, 2024
1 parent 0ba4714 commit db5c9f4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/transfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,14 @@ static CURLcode readwrite_data(struct Curl_easy *data,
buf = xfer_buf;
bytestoread = xfer_blen;

/* Observe any imposed speed limit */
if(bytestoread && data->set.max_recv_speed) {
curl_off_t net_limit = data->set.max_recv_speed - total_received;
if(net_limit <= 0)
/* In case of speed limit on receiving: if this loop already got
* data, break out. If not, limit the amount of bytes to receive.
* The overall, timed, speed limiting is done in multi.c */
if(total_received)
break;
if((size_t)net_limit < bytestoread)
bytestoread = (size_t)net_limit;
if((size_t)data->set.max_recv_speed < bytestoread)
bytestoread = (size_t)data->set.max_recv_speed;
}

nread = Curl_xfer_recv_resp(data, buf, bytestoread,
Expand Down

0 comments on commit db5c9f4

Please sign in to comment.