summaryrefslogtreecommitdiff
path: root/lib/easy.c
diff options
context:
space:
mode:
authorBrad G <43330364+bakedpotat0@users.noreply.github.com>2018-11-29 12:17:21 -0600
committerDaniel Stenberg <daniel@haxx.se>2018-12-16 18:46:01 +0100
commit306a47cea67f29a1c7a19a42de85e66acb03f1d7 (patch)
tree61ffad27ec4f7a2d4e155a64d2fa3ad37b9725b7 /lib/easy.c
parent9e6518481cd4e2603b4f9e04d6cfd1a214a72726 (diff)
downloadcurl-TFO-windows.tar.gz
connect: Add TCP Fast Open support for WindowsTFO-windows
This is the former PR #3327, saved by Johannes Schindelin, rebased, squashed and pushed again. Requires Windows 10 ver 1607 or newer
Diffstat (limited to 'lib/easy.c')
-rw-r--r--lib/easy.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/easy.c b/lib/easy.c
index e592d7a71..a3d04e062 100644
--- a/lib/easy.c
+++ b/lib/easy.c
@@ -104,6 +104,12 @@ static CURLcode win32_init(void)
WSADATA wsaData;
int res;
+#ifdef HAVE_CONNECTEX
+ curl_socket_t sockfd;
+ GUID guid = WSAID_CONNECTEX;
+ DWORD dummy_val;
+#endif
+
#if defined(ENABLE_IPV6) && (USE_WINSOCK < 2)
Error IPV6_requires_winsock2
#endif
@@ -132,9 +138,31 @@ static CURLcode win32_init(void)
return CURLE_FAILED_INIT;
}
/* The Windows Sockets DLL is acceptable. Proceed. */
+
+ /* Init pointer to ConnectEx(), a Winsock 2 function needed */
+ /* for TCP Fast Open support */
+#ifdef HAVE_CONNECTEX
+ Curl_ConnectEx = NULL;
+ sockfd = socket(AF_INET, SOCK_STREAM, 0);
+
+ if(sockfd != CURL_SOCKET_BAD) {
+ if(WSAIoctl(sockfd, SIO_GET_EXTENSION_FUNCTION_POINTER,
+ &guid, sizeof(guid),
+ &Curl_ConnectEx, sizeof(Curl_ConnectEx),
+ &dummy_val, NULL, NULL)) {
+ DEBUGF(fprintf(stderr,
+ "WSAIoctl() failed to return ConnectEx() ptr, err #%d\n",
+ WSAGetLastError()));
+ Curl_ConnectEx = NULL;
+ }
+
+ sclose(sockfd);
+ }
+
+#endif /* HAVE_CONNECTEX */
#elif defined(USE_LWIPSOCK)
lwip_init();
-#endif
+#endif /* USE_WINSOCK */
#ifdef USE_WINDOWS_SSPI
{
@@ -181,6 +209,12 @@ curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
#if defined(WIN32) && defined(UNICODE)
curl_wcsdup_callback Curl_cwcsdup = (curl_wcsdup_callback)_wcsdup;
#endif
+#ifdef HAVE_CONNECTEX
+/*
+ * ConnectEx pointer is initialized by win32_init() after Winsock init
+ */
+curl_ConnectEx_callback Curl_ConnectEx;
+#endif
#else
/*
* Symbian OS doesn't support initialization to code in writable static data.