From e67dff32ced4be1ec0a8539c29fd44bee9077923 Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Thu, 13 Sep 2012 01:53:42 +0200 Subject: Set errno to EINPROGRESS on Windows when the connect() call does not complete immediately, to simulate unix behavior This makes code that checks errno to determine whether connect() has succeeded or not work properly on Windows Fixes #298 reported by @butaman --- src/socketengine.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/socketengine.cpp b/src/socketengine.cpp index 72075dd49..ccaa71aed 100644 --- a/src/socketengine.cpp +++ b/src/socketengine.cpp @@ -208,7 +208,12 @@ int SocketEngine::SendTo(EventHandler* fd, const void *buf, size_t len, int flag int SocketEngine::Connect(EventHandler* fd, const sockaddr *serv_addr, socklen_t addrlen) { - return connect(fd->GetFd(), serv_addr, addrlen); + int ret = connect(fd->GetFd(), serv_addr, addrlen); +#ifdef WINDOWS + if ((ret == SOCKET_ERROR) && (WSAGetLastError() == WSAEWOULDBLOCK)) + errno = EINPROGRESS; +#endif + return ret; } int SocketEngine::Shutdown(EventHandler* fd, int how) -- cgit v1.2.3