Skip to content
Permalink
Browse files

windows: implement send buffer tuning

Significantly enhances upload performance on modern Windows versions.

Bug: https://curl.haxx.se/mail/lib-2018-07/0080.html
Closes #2762
Fixes #2224
  • Loading branch information...
Daniel Jelinski authored and bagder committed Jul 19, 2018
1 parent 298d256 commit 1ba1dba76a8898d1de4dfbc9f1910a352d8a9dab
Showing with 18 additions and 1 deletion.
  1. +18 −1 lib/transfer.c
@@ -869,6 +869,22 @@ static CURLcode done_sending(struct connectdata *conn,
return CURLE_OK;
}

#if defined(WIN32) && defined(SIO_IDEAL_SEND_BACKLOG_QUERY)
static void win_update_buffer_size(curl_socket_t sockfd)
{
int result;
ULONG ideal;
DWORD ideallen;
result = WSAIoctl(sockfd, SIO_IDEAL_SEND_BACKLOG_QUERY, 0, 0,
&ideal, sizeof(ideal), &ideallen, 0, 0);
if(result == 0) {
setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF,
(const char *)&ideal, sizeof(ideal));
}
}
#else
#define win_update_buffer_size(x)
#endif

/*
* Send data to upload to the server, when the socket is writable.
@@ -1020,10 +1036,11 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
k->upload_fromhere, /* buffer pointer */
k->upload_present, /* buffer size */
&bytes_written); /* actually sent */

if(result)
return result;

win_update_buffer_size(conn->writesockfd);

if(data->set.verbose)
/* show the data before we change the pointer upload_fromhere */
Curl_debug(data, CURLINFO_DATA_OUT, k->upload_fromhere,

1 comment on commit 1ba1dba

@gvanem

This comment has been minimized.

Copy link
Member

commented on 1ba1dba Oct 22, 2018

This broke USE_LWIPSOCK on Windows. Isn't it better to do:

--- a/transfer.c 2018-10-19 23:11:56
+++ b/transfer.c 2018-10-22 12:03:22
@@ -879,7 +879,7 @@
   return CURLE_OK;
 }

-#ifdef WIN32
+#if defined(_WIN32) && !defined(USE_LWIPSOCK)
 #ifndef SIO_IDEAL_SEND_BACKLOG_QUERY
 #define SIO_IDEAL_SEND_BACKLOG_QUERY 0x4004747B
 #endif
Please sign in to comment.
You can’t perform that action at this time.