From 306a47cea67f29a1c7a19a42de85e66acb03f1d7 Mon Sep 17 00:00:00 2001 From: Brad G <43330364+bakedpotat0@users.noreply.github.com> Date: Thu, 29 Nov 2018 12:17:21 -0600 Subject: connect: Add TCP Fast Open support for Windows This is the former PR #3327, saved by Johannes Schindelin, rebased, squashed and pushed again. Requires Windows 10 ver 1607 or newer --- lib/sendf.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'lib/sendf.c') diff --git a/lib/sendf.c b/lib/sendf.c index e8598e617..2a4db3971 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -387,6 +387,37 @@ ssize_t Curl_send_plain(struct connectdata *conn, int num, conn->bits.tcp_fastopen = FALSE; } else +#elif defined(HAVE_CONNECTEX) + if(conn->bits.tcp_fastopen && !conn->fastopen_connected) { + conn->fastopen_connected = TRUE; + bytes_written = 0; + + if(!Curl_ConnectEx(sockfd, + conn->ip_addr->ai_addr, conn->ip_addr->ai_addrlen, + (void *)mem, (DWORD)len, + (LPDWORD)&bytes_written, + &conn->fastopen_state)) { + if(SOCKERRNO != WSA_IO_PENDING) + bytes_written = -1; + else + if(!GetOverlappedResult((HANDLE)sockfd, &conn->fastopen_state, + (LPDWORD)&bytes_written, TRUE)) { + int err = GetLastError(); + failf(conn->data, "Send failure: %s", + Curl_strerror(conn, err)); + conn->data->state.os_errno = err; + *code = CURLE_SEND_ERROR; + return 0; + } + } + + /* socket in default state; enable previously-set socket params */ + if(setsockopt(sockfd, SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, NULL, 0)) + infof(conn->data, + "setsockopt() failed after TCP Fast Open for fd %d, errno: %d", + sockfd, SOCKERRNO); + } + else #endif bytes_written = swrite(sockfd, mem, len); -- cgit v1.2.1