summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-04-27 12:13:06 +0200
committerCharles Pigott <charlespigott@googlemail.com>2021-04-27 18:17:34 +0100
commitcf8c1aa860e05e696f9829e3b031a22ca82781ef (patch)
tree83e6146c63fc892142b5f67c45f7bfc8cd98b552
parent65c5a647191a9a10a532bb9d67da6938f5eace1b (diff)
downloadopenttd-cf8c1aa860e05e696f9829e3b031a22ca82781ef.tar.xz
Change: [Network] Use string error messages instead of numeric error numbers that need to be looked up
-rw-r--r--src/network/core/os_abstraction.h2
-rw-r--r--src/network/core/tcp.cpp10
-rw-r--r--src/network/core/tcp_http.cpp4
-rw-r--r--src/network/core/tcp_listen.h4
-rw-r--r--src/network/core/udp.cpp4
5 files changed, 13 insertions, 11 deletions
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<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);
break;
@@ -81,7 +81,7 @@ public:
p.PrepareToSend();
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);
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;
}