Ignore some socket errors that may be caused by transient network interruptions

This allows the ENet connection to survive WiFi network roaming.
This commit is contained in:
Cameron Gutman
2024-01-24 23:22:19 -06:00
parent c6bb0e5011
commit acf813c4aa
2 changed files with 38 additions and 6 deletions
+19 -3
View File
@@ -655,10 +655,26 @@ enet_socket_send (ENetSocket socket,
if (sentLength == -1)
{
if (errno == EWOULDBLOCK)
return 0;
switch (errno)
{
case EWOULDBLOCK:
return 0;
return -1;
// These errors are treated as possible transient
// conditions that could be caused by a network
// interruption. We'll ignore them and allow the
// socket timeout to kill us if the connection
// is permanently interrupted.
case EADDRNOTAVAIL:
case ENETDOWN:
case ENETUNREACH:
case EHOSTDOWN:
case EHOSTUNREACH:
return 0;
default:
return -1;
}
}
return sentLength;
+19 -3
View File
@@ -496,10 +496,26 @@ enet_socket_send (ENetSocket socket,
NULL,
NULL) == SOCKET_ERROR)
{
if (WSAGetLastError () == WSAEWOULDBLOCK)
return 0;
switch (WSAGetLastError ())
{
case WSAEWOULDBLOCK:
return 0;
return -1;
// These errors are treated as possible transient
// conditions that could be caused by a network
// interruption. We'll ignore them and allow the
// socket timeout to kill us if the connection
// is permanently interrupted.
case WSAEADDRNOTAVAIL:
case WSAENETDOWN:
case WSAENETUNREACH:
case WSAEHOSTDOWN:
case WSAEHOSTUNREACH:
return 0;
default:
return -1;
}
}
return (int) sentLength;