Skip to content

Commit

Permalink
Clean up macro redefinition warning in pnSocket.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
zrax committed Oct 2, 2023
1 parent d988343 commit e209d76
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions net/pnSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
#include "Debug/plDebug.h"
#include <cstring>

static const char* getSockErrorStr();
static int sockError();

#ifdef _WIN32
# include <winsock2.h>
# include <ws2tcpip.h>
Expand All @@ -33,8 +30,6 @@ static int sockError();

static void closeWinsock() { WSACleanup(); }

static int sockError() { return WSAGetLastError(); }

# ifndef AI_ADDRCONFIG
# define AI_ADDRCONFIG 0x0020
# endif
Expand All @@ -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 <sys/filio.h>
Expand All @@ -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
Expand Down Expand Up @@ -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();
}
Expand All @@ -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;
}
Expand Down

0 comments on commit e209d76

Please sign in to comment.