diff --git a/lib/client-handshake.c b/lib/client-handshake.c index cd93a0b9..004ed939 100644 --- a/lib/client-handshake.c +++ b/lib/client-handshake.c @@ -136,7 +136,7 @@ struct libwebsocket *libwebsocket_client_connect_2( freeaddrinfo(result); } - if (wsi->sock < 0) { + if (!lws_socket_is_valid(wsi->sock)) { #ifdef LWS_USE_IPV6 if (LWS_IPV6_ENABLED(context)) @@ -145,7 +145,7 @@ struct libwebsocket *libwebsocket_client_connect_2( #endif wsi->sock = socket(AF_INET, SOCK_STREAM, 0); - if (wsi->sock < 0) { + if (!lws_socket_is_valid(wsi->sock)) { lwsl_warn("Unable to open socket\n"); goto oom4; } diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index a96e2952..6a31dcae 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -71,6 +71,8 @@ amount = _amount; \ } #define lws_set_blocking_send(wsi) wsi->sock_send_blocking = TRUE +#define lws_socket_is_valid(x) (!!x) +#define LWS_SOCK_INVALID 0 #include #include #include @@ -143,6 +145,8 @@ #define compatible_file_read(amount, fd, buf, len) \ amount = read(fd, buf, len); #define lws_set_blocking_send(wsi) +#define lws_socket_is_valid(x) (x >= 0) +#define LWS_SOCK_INVALID (-1) #endif #ifndef LWS_HAVE_BZERO diff --git a/lib/server.c b/lib/server.c index b98bf1e9..0b46402f 100644 --- a/lib/server.c +++ b/lib/server.c @@ -618,7 +618,8 @@ libwebsocket_create_new_server_wsi(struct libwebsocket_context *context) new_wsi->protocol = context->protocols; new_wsi->user_space = NULL; new_wsi->ietf_spec_revision = 0; - + new_wsi->sock = LWS_SOCK_INVALID; + /* * outermost create notification for wsi * no user_space because no protocol selection