From cabb98c6c174f300010f042756f9befffda98779 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, and that will be reported separately). 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. Closes #xxxx --- 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 69df214ce47f22..27843f50cc1f0c 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 4cfffa773703ae..29504df4e7a3fd 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -689,6 +689,10 @@ struct SingleRequest { #endif unsigned char setcookies; unsigned char writer_stack_depth; /* Unencoding stack depth. */ +#if defined(WIN32) && defined(USE_WINSOCK) + struct curltime last_sndbuf_update; /* last time readwrite_upload called + win_update_buffer_size */ +#endif BIT(header); /* incoming data has HTTP header */ BIT(content_range); /* set TRUE if Content-Range: was found */ BIT(upload_done); /* set to TRUE when doing chunked transfer-encoding