From cf8c1aa860e05e696f9829e3b031a22ca82781ef Mon Sep 17 00:00:00 2001 From: rubidium42 Date: Tue, 27 Apr 2021 12:13:06 +0200 Subject: Change: [Network] Use string error messages instead of numeric error numbers that need to be looked up --- src/network/core/os_abstraction.h | 2 ++ src/network/core/tcp.cpp | 10 +++++----- src/network/core/tcp_http.cpp | 4 ++-- src/network/core/tcp_listen.h | 4 ++-- src/network/core/udp.cpp | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/network/core/os_abstraction.h b/src/network/core/os_abstraction.h index a015c4374..7af3fd163 100644 --- a/src/network/core/os_abstraction.h +++ b/src/network/core/os_abstraction.h @@ -31,6 +31,8 @@ #define NetworkGetLastError() WSAGetLastError() #undef EWOULDBLOCK #define EWOULDBLOCK WSAEWOULDBLOCK +#undef ECONNRESET +#define ECONNRESET WSAECONNRESET const char *NetworkGetErrorString(int error); diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp index b9ba33f00..f23b202c8 100644 --- a/src/network/core/tcp.cpp +++ b/src/network/core/tcp.cpp @@ -90,7 +90,7 @@ SendPacketsState NetworkTCPSocketHandler::SendPackets(bool closing_down) if (err != EWOULDBLOCK) { /* Something went wrong.. close client! */ if (!closing_down) { - DEBUG(net, 0, "send failed with error %d", err); + DEBUG(net, 0, "send failed with error %s", NetworkGetErrorString(err)); this->CloseConnection(); } return SPS_CLOSED; @@ -138,8 +138,8 @@ Packet *NetworkTCPSocketHandler::ReceivePacket() if (res == -1) { int err = NetworkGetLastError(); if (err != EWOULDBLOCK) { - /* Something went wrong... (104 is connection reset by peer) */ - if (err != 104) DEBUG(net, 0, "recv failed with error %d", err); + /* Something went wrong... (ECONNRESET is connection reset by peer) */ + if (err != ECONNRESET) DEBUG(net, 0, "recv failed with error %s", NetworkGetErrorString(err)); this->CloseConnection(); return nullptr; } @@ -166,8 +166,8 @@ Packet *NetworkTCPSocketHandler::ReceivePacket() if (res == -1) { int err = NetworkGetLastError(); if (err != EWOULDBLOCK) { - /* Something went wrong... (104 is connection reset by peer) */ - if (err != 104) DEBUG(net, 0, "recv failed with error %d", err); + /* Something went wrong... (ECONNRESET is connection reset by peer) */ + if (err != ECONNRESET) DEBUG(net, 0, "recv failed with error %s", NetworkGetErrorString(err)); this->CloseConnection(); return nullptr; } diff --git a/src/network/core/tcp_http.cpp b/src/network/core/tcp_http.cpp index 04bc6a03a..d57f4eceb 100644 --- a/src/network/core/tcp_http.cpp +++ b/src/network/core/tcp_http.cpp @@ -230,8 +230,8 @@ int NetworkHTTPSocketHandler::Receive() if (res == -1) { int err = NetworkGetLastError(); if (err != EWOULDBLOCK) { - /* Something went wrong... (104 is connection reset by peer) */ - if (err != 104) DEBUG(net, 0, "recv failed with error %d", err); + /* Something went wrong... (ECONNRESET is connection reset by peer) */ + if (err != ECONNRESET) DEBUG(net, 0, "recv failed with error %s", NetworkGetErrorString(err)); return -1; } /* Connection would block, so stop for now */ diff --git a/src/network/core/tcp_listen.h b/src/network/core/tcp_listen.h index c11727ba7..168f49f94 100644 --- a/src/network/core/tcp_listen.h +++ b/src/network/core/tcp_listen.h @@ -64,7 +64,7 @@ public: DEBUG(net, 1, "[%s] Banned ip tried to join (%s), refused", Tsocket::GetName(), entry.c_str()); if (p.TransferOut(send, s, 0) < 0) { - DEBUG(net, 0, "send failed with error %d", NetworkGetLastError()); + DEBUG(net, 0, "send failed with error %s", NetworkGetLastErrorString()); } closesocket(s); break; @@ -81,7 +81,7 @@ public: p.PrepareToSend(); if (p.TransferOut(send, s, 0) < 0) { - DEBUG(net, 0, "send failed with error %d", NetworkGetLastError()); + DEBUG(net, 0, "send failed with error %s", NetworkGetLastErrorString()); } closesocket(s); diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp index abbb1bbdb..df5140e2b 100644 --- a/src/network/core/udp.cpp +++ b/src/network/core/udp.cpp @@ -94,7 +94,7 @@ void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool a /* Enable broadcast */ unsigned long val = 1; if (setsockopt(s.second, SOL_SOCKET, SO_BROADCAST, (char *) &val, sizeof(val)) < 0) { - DEBUG(net, 1, "[udp] setting broadcast failed with: %i", NetworkGetLastError()); + DEBUG(net, 1, "[udp] setting broadcast failed with: %s", NetworkGetLastErrorString()); } } @@ -103,7 +103,7 @@ void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool a DEBUG(net, 7, "[udp] sendto(%s)", send.GetAddressAsString().c_str()); /* Check for any errors, but ignore it otherwise */ - if (res == -1) DEBUG(net, 1, "[udp] sendto(%s) failed with: %i", send.GetAddressAsString().c_str(), NetworkGetLastError()); + if (res == -1) DEBUG(net, 1, "[udp] sendto(%s) failed with: %s", send.GetAddressAsString().c_str(), NetworkGetLastErrorString()); if (!all) break; } -- cgit v1.2.3-70-g09d2