From 3200040d1afa97a1fcc56c198111f0d75bb8432a Mon Sep 17 00:00:00 2001 From: David Garske Date: Fri, 27 Apr 2018 10:21:20 -0700 Subject: [PATCH] Cleanup of the socket close code used for examples, CRL/OCSP and BIO. Now only a single macro is responsible for closing a socket `CloseSocket` and all duplicate code is eliminated. --- src/ssl.c | 10 ---------- src/wolfio.c | 4 ++-- wolfssl/test.h | 11 ----------- wolfssl/wolfio.h | 15 ++++++++++++++- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index 675f66859..2d33b4d7a 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -11563,16 +11563,6 @@ int wolfSSL_set_compression(WOLFSSL* ssl) return bio; } - -#ifdef USE_WINDOWS_API - #define CloseSocket(s) closesocket(s) -#elif defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET) - #define CloseSocket(s) closesocket(s) - extern int closesocket(int); -#else - #define CloseSocket(s) close(s) -#endif - /* * Note : If the flag BIO_NOCLOSE is set then freeing memory buffers is up * to the application. diff --git a/src/wolfio.c b/src/wolfio.c index 66b00ea64..053d7f453 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -1337,7 +1337,7 @@ int EmbedOcspLookup(void* ctx, const char* url, int urlSz, HTTP_SCRATCH_BUFFER_SIZE, ctx); } - close(sfd); + CloseSocket(sfd); XFREE(httpBuf, ctx, DYNAMIC_TYPE_OCSP); } } @@ -1438,7 +1438,7 @@ int EmbedCrlLookup(WOLFSSL_CRL* crl, const char* url, int urlSz) HTTP_SCRATCH_BUFFER_SIZE); } - close(sfd); + CloseSocket(sfd); XFREE(httpBuf, crl->heap, DYNAMIC_TYPE_CRL); } } diff --git a/wolfssl/test.h b/wolfssl/test.h index 6aea1f491..c52ff38f0 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -183,17 +183,6 @@ #endif -#ifdef USE_WINDOWS_API - #define CloseSocket(s) closesocket(s) - #define StartTCP() { WSADATA wsd; WSAStartup(0x0002, &wsd); } -#elif defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET) - #define CloseSocket(s) closesocket(s) - #define StartTCP() -#else - #define CloseSocket(s) close(s) - #define StartTCP() -#endif - #ifdef SINGLE_THREADED typedef unsigned int THREAD_RETURN; diff --git a/wolfssl/wolfio.h b/wolfssl/wolfio.h index 443ebc2f9..f14f7df1b 100644 --- a/wolfssl/wolfio.h +++ b/wolfssl/wolfio.h @@ -147,7 +147,6 @@ #define SOCKET_EPIPE WSAEPIPE #define SOCKET_ECONNREFUSED WSAENOTCONN #define SOCKET_ECONNABORTED WSAECONNABORTED - #define close(s) closesocket(s) #elif defined(__PPU) #define SOCKET_EWOULDBLOCK SYS_NET_EWOULDBLOCK #define SOCKET_EAGAIN SYS_NET_EAGAIN @@ -210,6 +209,20 @@ #endif /* USE_WINDOWS_API */ +#ifdef USE_WINDOWS_API + #define CloseSocket(s) closesocket(s) + #define StartTCP() { WSADATA wsd; WSAStartup(0x0002, &wsd); } +#elif defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET) + extern int closesocket(int); + #define CloseSocket(s) closesocket(s) + #define StartTCP() +#else + #define CloseSocket(s) close(s) + #define StartTCP() +#endif + + + #ifdef DEVKITPRO /* from network.h */ int net_send(int, const void*, int, unsigned int);