From 9fd507d60b91edacaea936d290da2cc5657efeef Mon Sep 17 00:00:00 2001
From: Daniel Jelinski <daniel.jelinski@thomsonreuters.com>
Date: Thu, 19 Jul 2018 14:07:59 +0200
Subject: [PATCH] Implement send buffer tuning under Windows

---
 lib/transfer.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lib/transfer.c b/lib/transfer.c
index 435d3e1..626d404 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -869,6 +869,18 @@ static CURLcode done_sending(struct connectdata *conn,
   return CURLE_OK;
 }
 
+#ifdef SIO_IDEAL_SEND_BACKLOG_QUERY
+static void	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));
+  }
+}
+#endif
 
 /*
  * Send data to upload to the server, when the socket is writable.
@@ -1020,6 +1032,9 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
                         k->upload_fromhere, /* buffer pointer */
                         k->upload_present,  /* buffer size */
                         &bytes_written);    /* actually sent */
+#ifdef SIO_IDEAL_SEND_BACKLOG_QUERY
+    update_buffer_size(conn->writesockfd);
+#endif
 
     if(result)
       return result;
-- 
2.6.3.windows.1

