From 236bc6bc4edbecdc5f31367b70f9ea3ba6b804e3 Mon Sep 17 00:00:00 2001 From: Patrick Gansterer Date: Thu, 27 Mar 2014 11:21:41 +0100 Subject: [PATCH] Fix nonblocking connect on Windows Use the correct value for the call to ioctlsocket() to set the socket to nonblocking mode and check for WSAWOULDBLOCK return value of connect(). --- lib/client-handshake.c | 3 ++- lib/libwebsockets.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/client-handshake.c b/lib/client-handshake.c index f80b9b4878..2fec991c4f 100644 --- a/lib/client-handshake.c +++ b/lib/client-handshake.c @@ -177,7 +177,8 @@ struct libwebsocket *libwebsocket_client_connect_2( if (connect(wsi->sock, v, n) == -1 || LWS_ERRNO == LWS_EISCONN) { - if (LWS_ERRNO == LWS_EALREADY || LWS_ERRNO == LWS_EINPROGRESS) { + if (LWS_ERRNO == LWS_EALREADY || LWS_ERRNO == LWS_EINPROGRESS + || LWS_ERRNO == LWS_EWOULDBLOCK) { lwsl_client("nonblocking connect retry\n"); /* diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index bb13069749..520aa6b887 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -694,7 +694,7 @@ int lws_set_socket_options(struct libwebsocket_context *context, int fd) int optval = 1; socklen_t optlen = sizeof(optval); #if defined(WIN32) || defined(_WIN32) - unsigned long optl = 0; + u_long optl = 1; #endif #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) struct protoent *tcp_proto;