From 0b84d0cf1bf726189a4ecf3339735ac2f6b404f4 Mon Sep 17 00:00:00 2001 From: Jay Satiro Date: Sun, 26 Feb 2023 03:44:38 -0500 Subject: [PATCH] transfer: limit Windows SO_SNDBUF updates to once a second - Change readwrite_upload() to call win_update_buffer_size() no more than once a second to update SO_SNDBUF (send buffer limit). Prior to this change during an upload readwrite_upload() could call win_update_buffer_size() anywhere from hundreds of times per second to an extreme test case of 100k per second (which is likely due to a bug, see #10618). In the latter case WPA profiler showed win_update_buffer_size was the highest capture count in readwrite_upload. In any case the calls were excessive and unnecessary. Ref: https://github.com/curl/curl/pull/2762 Closes https://github.com/curl/curl/pull/10611 --- lib/transfer.c | 10 +++++++++- lib/urldata.h | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/transfer.c b/lib/transfer.c index 69df214ce4..27843f50cc 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -980,7 +980,15 @@ static CURLcode readwrite_upload(struct Curl_easy *data, if(result) return result; - win_update_buffer_size(conn->writesockfd); +#if defined(WIN32) && defined(USE_WINSOCK) + { + struct curltime n = Curl_now(); + if(Curl_timediff(n, k->last_sndbuf_update) > 1000) { + win_update_buffer_size(conn->writesockfd); + k->last_sndbuf_update = n; + } + } +#endif if(k->pendingheader) { /* parts of what was sent was header */ diff --git a/lib/urldata.h b/lib/urldata.h index ca8e3074d7..d7d104d419 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -686,6 +686,10 @@ struct SingleRequest { } p; #ifndef CURL_DISABLE_DOH struct dohdata *doh; /* DoH specific data for this request */ +#endif +#if defined(WIN32) && defined(USE_WINSOCK) + struct curltime last_sndbuf_update; /* last time readwrite_upload called + win_update_buffer_size */ #endif unsigned char setcookies; unsigned char writer_stack_depth; /* Unencoding stack depth. */ -- 2.47.3