diff --git a/lib/client-handshake.c b/lib/client-handshake.c index bcc4edba..34c29c80 100644 --- a/lib/client-handshake.c +++ b/lib/client-handshake.c @@ -79,11 +79,7 @@ struct libwebsocket *__libwebsocket_client_connect_2( if (connect(wsi->sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) { lwsl_debug("Connect failed\n"); -#ifdef WIN32 - closesocket(wsi->sock); -#else - close(wsi->sock); -#endif + compatible_close(wsi->sock); goto oom4; } @@ -110,11 +106,7 @@ struct libwebsocket *__libwebsocket_client_connect_2( n = send(wsi->sock, pkt, plen, 0); if (n < 0) { -#ifdef WIN32 - closesocket(wsi->sock); -#else - close(wsi->sock); -#endif + compatible_close(wsi->sock); lwsl_debug("ERROR writing to proxy socket\n"); goto bail1; } diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index c084cfc5..4cc70b46 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -392,22 +392,14 @@ just_kill_connection: if (wsi->ssl) { n = SSL_get_fd(wsi->ssl); SSL_shutdown(wsi->ssl); -#ifdef WIN32 - closesocket(n); -#else - close(n); -#endif + compatible_close(n); SSL_free(wsi->ssl); } else { #endif shutdown(wsi->sock, SHUT_RDWR); -#ifdef WIN32 + if (wsi->sock) - closesocket(wsi->sock); -#else - if (wsi->sock) - close(wsi->sock); -#endif + compatible_close(wsi->sock); #ifdef LWS_OPENSSL_SUPPORT } #endif @@ -1585,21 +1577,13 @@ libwebsocket_service_fd(struct libwebsocket_context *context, LWS_CALLBACK_FILTER_NETWORK_CONNECTION, (void *)(long)accept_fd, NULL, 0)) { lwsl_debug("Callback denied network connection\n"); -#ifdef WIN32 - closesocket(accept_fd); -#else - close(accept_fd); -#endif + compatible_close(accept_fd); break; } new_wsi = libwebsocket_create_new_server_wsi(context); if (new_wsi == NULL) { -#ifdef WIN32 - closesocket(accept_fd); -#else - close(accept_fd); -#endif + compatible_close(accept_fd); break; } @@ -1618,11 +1602,7 @@ libwebsocket_service_fd(struct libwebsocket_context *context, new_wsi->ssl, 0), NULL)); libwebsockets_decode_ssl_error(); free(new_wsi); -#ifdef WIN32 - closesocket(accept_fd); -#else - close(accept_fd); -#endif + compatible_close(accept_fd); break; } @@ -1645,11 +1625,7 @@ libwebsocket_service_fd(struct libwebsocket_context *context, SSL_free( new_wsi->ssl); free(new_wsi); -#ifdef WIN32 - closesocket(accept_fd); -#else - close(accept_fd); -#endif + compatible_close(accept_fd); break; } @@ -1736,11 +1712,7 @@ libwebsocket_service_fd(struct libwebsocket_context *context, break; bail_prox_listener: -#ifdef WIN32 - closesocket(accept_fd); -#else - close(accept_fd); -#endif + compatible_close(accept_fd); break; case LWS_CONNMODE_BROADCAST_PROXY: diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index 6602c0e2..823ba7e7 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -40,6 +40,7 @@ #include #ifdef WIN32 +#define compatible_close(fd) closesocket(fd); #ifdef __MINGW64__ #else #ifdef __MINGW32__ @@ -50,9 +51,7 @@ #include #include #include - #else - #include #include #ifndef LWS_NO_FORK @@ -68,6 +67,7 @@ #include #include +#define compatible_close(fd) close(fd); #endif #ifdef LWS_OPENSSL_SUPPORT