From e209d76c819a12e3a902e72c3b33d905163ffb80 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Mon, 2 Oct 2023 12:03:16 -0700 Subject: [PATCH] Clean up macro redefinition warning in pnSocket.cpp --- net/pnSocket.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/net/pnSocket.cpp b/net/pnSocket.cpp index 3adaf74ff..f9b77a0b9 100644 --- a/net/pnSocket.cpp +++ b/net/pnSocket.cpp @@ -18,9 +18,6 @@ #include "Debug/plDebug.h" #include -static const char* getSockErrorStr(); -static int sockError(); - #ifdef _WIN32 # include # include @@ -33,8 +30,6 @@ static int sockError(); static void closeWinsock() { WSACleanup(); } - static int sockError() { return WSAGetLastError(); } - # ifndef AI_ADDRCONFIG # define AI_ADDRCONFIG 0x0020 # endif @@ -56,15 +51,9 @@ static int sockError(); typedef void* sockbuf_t; typedef const void* const_sockbuf_t; - static int sockError() { return errno; } - # define INVALID_SOCKET (-1) #endif -#ifdef _MSC_VER -# define ECONNRESET WSAECONNRESET -#endif - // For Solaris #ifdef NEED_FILIO # include @@ -83,6 +72,15 @@ static const char* getSockErrorStr() #endif } +static bool checkConnReset() +{ +#ifdef _MSC_VER + return WSAGetLastError() == WSAECONNRESET; +#else + return errno == ECONNRESET; +#endif +} + static void initSockets() { #ifdef _WIN32 @@ -245,7 +243,7 @@ long pnSocket::send(const void* buffer, size_t size) long pnSocket::recv(void* buffer, size_t size) { long count = ::recv(fSockHandle, (sockbuf_t)buffer, size, 0); - if (count == -1 && sockError() != ECONNRESET) { + if (count == -1 && !checkConnReset()) { plDebug::Error("Recv failed: {}", getSockErrorStr()); close(); } @@ -255,7 +253,7 @@ long pnSocket::recv(void* buffer, size_t size) long pnSocket::peek(void* buffer, size_t size) { long count = ::recv(fSockHandle, (sockbuf_t)buffer, size, MSG_PEEK); - if (count == -1 && sockError() != ECONNRESET) + if (count == -1 && !checkConnReset()) plDebug::Error("Peek failed: {}", getSockErrorStr()); return count; }