Changeset - r25278:bfc017f0c065
[Not reviewed]
master
0 5 0
rubidium42 - 3 years ago 2021-04-27 10:13:06
rubidium@openttd.org
Change: [Network] Use string error messages instead of numeric error numbers that need to be looked up
5 files changed with 13 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/network/core/os_abstraction.h
Show inline comments
 
@@ -31,6 +31,8 @@
 
#define NetworkGetLastError() WSAGetLastError()
 
#undef EWOULDBLOCK
 
#define EWOULDBLOCK WSAEWOULDBLOCK
 
#undef ECONNRESET
 
#define ECONNRESET WSAECONNRESET
 

	
 
const char *NetworkGetErrorString(int error);
 

	
src/network/core/tcp.cpp
Show inline comments
 
@@ -90,7 +90,7 @@ SendPacketsState NetworkTCPSocketHandler
 
			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::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));
 
					this->CloseConnection();
 
					return nullptr;
 
				}
 
@@ -166,8 +166,8 @@ Packet *NetworkTCPSocketHandler::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));
 
				this->CloseConnection();
 
				return nullptr;
 
			}
src/network/core/tcp_http.cpp
Show inline comments
 
@@ -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 */
src/network/core/tcp_listen.h
Show inline comments
 
@@ -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);
 

	
src/network/core/udp.cpp
Show inline comments
 
@@ -94,7 +94,7 @@ void NetworkUDPSocketHandler::SendPacket
 
			/* 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
 
		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;
 
	}
0 comments (0 inline, 0 general)