From b177bffa6a5f1b69639b6cd759dcb16fdd76e5e2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 24 Oct 2017 20:09:11 +0200 Subject: [PATCH] system/EventPipe: fix WSAEINPROGRESS on Windows Apparently, connecting a socket to a loopback address can block on Windows, and a non-blocking socket will return WSAEINPROGRESS. This broken PoorSocketPair() in commit 2119e4fd3ef, which made the socket non-blocking right from the start. This fix postpones the ioctlsocket(FIONBIO) call until after the connect(). Closes #134 --- src/system/EventPipe.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/system/EventPipe.cxx b/src/system/EventPipe.cxx index 177e55347..e56534e2a 100644 --- a/src/system/EventPipe.cxx +++ b/src/system/EventPipe.cxx @@ -113,12 +113,14 @@ PoorSocketPair(int fd[2]) throw MakeSocketError("Failed to listen on socket"); UniqueSocketDescriptor socket0; - if (!socket0.CreateNonBlock(AF_INET, SOCK_STREAM, IPPROTO_TCP)) + if (!socket0.Create(AF_INET, SOCK_STREAM, IPPROTO_TCP)) throw MakeSocketError("Failed to create socket"); if (!socket0.Connect(listen_socket.GetLocalAddress())) throw MakeSocketError("Failed to connect socket"); + socket0.SetNonBlocking(); + auto socket1 = listen_socket.AcceptNonBlock(); if (!socket1.IsDefined()) throw MakeSocketError("Failed to accept connection");