1
0
Fork 0

Change: [Network] Use string error messages instead of numeric error numbers that need to be looked up

pull/9122/head
rubidium42 2021-04-27 12:13:06 +02:00 committed by Charles Pigott
parent 65c5a64719
commit cf8c1aa860
5 changed files with 13 additions and 11 deletions

View File

@ -31,6 +31,8 @@
#define NetworkGetLastError() WSAGetLastError() #define NetworkGetLastError() WSAGetLastError()
#undef EWOULDBLOCK #undef EWOULDBLOCK
#define EWOULDBLOCK WSAEWOULDBLOCK #define EWOULDBLOCK WSAEWOULDBLOCK
#undef ECONNRESET
#define ECONNRESET WSAECONNRESET
const char *NetworkGetErrorString(int error); const char *NetworkGetErrorString(int error);

View File

@ -90,7 +90,7 @@ SendPacketsState NetworkTCPSocketHandler::SendPackets(bool closing_down)
if (err != EWOULDBLOCK) { if (err != EWOULDBLOCK) {
/* Something went wrong.. close client! */ /* Something went wrong.. close client! */
if (!closing_down) { if (!closing_down) {
DEBUG(net, 0, "send failed with error %d", err); DEBUG(net, 0, "send failed with error %s", NetworkGetErrorString(err));
this->CloseConnection(); this->CloseConnection();
} }
return SPS_CLOSED; return SPS_CLOSED;
@ -138,8 +138,8 @@ Packet *NetworkTCPSocketHandler::ReceivePacket()
if (res == -1) { if (res == -1) {
int err = NetworkGetLastError(); int err = NetworkGetLastError();
if (err != EWOULDBLOCK) { if (err != EWOULDBLOCK) {
/* Something went wrong... (104 is connection reset by peer) */ /* Something went wrong... (ECONNRESET is connection reset by peer) */
if (err != 104) DEBUG(net, 0, "recv failed with error %d", err); if (err != ECONNRESET) DEBUG(net, 0, "recv failed with error %s", NetworkGetErrorString(err));
this->CloseConnection(); this->CloseConnection();
return nullptr; return nullptr;
} }
@ -166,8 +166,8 @@ Packet *NetworkTCPSocketHandler::ReceivePacket()
if (res == -1) { if (res == -1) {
int err = NetworkGetLastError(); int err = NetworkGetLastError();
if (err != EWOULDBLOCK) { if (err != EWOULDBLOCK) {
/* Something went wrong... (104 is connection reset by peer) */ /* Something went wrong... (ECONNRESET is connection reset by peer) */
if (err != 104) DEBUG(net, 0, "recv failed with error %d", err); if (err != ECONNRESET) DEBUG(net, 0, "recv failed with error %s", NetworkGetErrorString(err));
this->CloseConnection(); this->CloseConnection();
return nullptr; return nullptr;
} }

View File

@ -230,8 +230,8 @@ int NetworkHTTPSocketHandler::Receive()
if (res == -1) { if (res == -1) {
int err = NetworkGetLastError(); int err = NetworkGetLastError();
if (err != EWOULDBLOCK) { if (err != EWOULDBLOCK) {
/* Something went wrong... (104 is connection reset by peer) */ /* Something went wrong... (ECONNRESET is connection reset by peer) */
if (err != 104) DEBUG(net, 0, "recv failed with error %d", err); if (err != ECONNRESET) DEBUG(net, 0, "recv failed with error %s", NetworkGetErrorString(err));
return -1; return -1;
} }
/* Connection would block, so stop for now */ /* Connection would block, so stop for now */

View File

@ -64,7 +64,7 @@ public:
DEBUG(net, 1, "[%s] Banned ip tried to join (%s), refused", Tsocket::GetName(), entry.c_str()); DEBUG(net, 1, "[%s] Banned ip tried to join (%s), refused", Tsocket::GetName(), entry.c_str());
if (p.TransferOut<int>(send, s, 0) < 0) { if (p.TransferOut<int>(send, s, 0) < 0) {
DEBUG(net, 0, "send failed with error %d", NetworkGetLastError()); DEBUG(net, 0, "send failed with error %s", NetworkGetLastErrorString());
} }
closesocket(s); closesocket(s);
break; break;
@ -81,7 +81,7 @@ public:
p.PrepareToSend(); p.PrepareToSend();
if (p.TransferOut<int>(send, s, 0) < 0) { if (p.TransferOut<int>(send, s, 0) < 0) {
DEBUG(net, 0, "send failed with error %d", NetworkGetLastError()); DEBUG(net, 0, "send failed with error %s", NetworkGetLastErrorString());
} }
closesocket(s); closesocket(s);

View File

@ -94,7 +94,7 @@ void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool a
/* Enable broadcast */ /* Enable broadcast */
unsigned long val = 1; unsigned long val = 1;
if (setsockopt(s.second, SOL_SOCKET, SO_BROADCAST, (char *) &val, sizeof(val)) < 0) { 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()); DEBUG(net, 7, "[udp] sendto(%s)", send.GetAddressAsString().c_str());
/* Check for any errors, but ignore it otherwise */ /* 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; if (!all) break;
} }