1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

replace ifdefs around close socket with compatible_close

Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
Andy Green 2013-01-14 15:35:02 +08:00
parent 455d1fed06
commit 3fc2c65d2f
3 changed files with 12 additions and 48 deletions

View file

@ -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;
}

View file

@ -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:

View file

@ -40,6 +40,7 @@
#include <sys/stat.h>
#ifdef WIN32
#define compatible_close(fd) closesocket(fd);
#ifdef __MINGW64__
#else
#ifdef __MINGW32__
@ -50,9 +51,7 @@
#include <winsock2.h>
#include <ws2ipdef.h>
#include <windows.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#ifndef LWS_NO_FORK
@ -68,6 +67,7 @@
#include <sys/mman.h>
#include <sys/time.h>
#define compatible_close(fd) close(fd);
#endif
#ifdef LWS_OPENSSL_SUPPORT