mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-08-18 09:25:49 +00:00
Ignore ICMP Port Unreachable messages on our UDP sockets
These messages can falsely indicate failure in cases where the UDP socket for audio or video hasn't opened yet when we start to send our PING packets. It is also problematic when sending STUN requests to multiple IP addresses. If one returns an ICMP Port Unreachable, it can cause us to fail the entire set of requests even when other IP addresses do respond.
This commit is contained in:
parent
7b024c967e
commit
6ca0b93809
@ -133,6 +133,7 @@ int pollSockets(struct pollfd* pollFds, int pollFdsCount, int timeoutMs) {
|
||||
int recvUdpSocket(SOCKET s, char* buffer, int size, int useSelect) {
|
||||
int err;
|
||||
|
||||
do {
|
||||
if (useSelect) {
|
||||
struct pollfd pfd;
|
||||
|
||||
@ -146,13 +147,13 @@ int recvUdpSocket(SOCKET s, char* buffer, int size, int useSelect) {
|
||||
}
|
||||
|
||||
// This won't block since the socket is readable
|
||||
return (int)recv(s, buffer, size, 0);
|
||||
err = (int)recvfrom(s, buffer, size, 0, NULL, NULL);
|
||||
}
|
||||
else {
|
||||
// The caller has already configured a timeout on this
|
||||
// socket via SO_RCVTIMEO, so we can avoid a syscall
|
||||
// for each packet.
|
||||
err = (int)recv(s, buffer, size, 0);
|
||||
err = (int)recvfrom(s, buffer, size, 0, NULL, NULL);
|
||||
if (err < 0 &&
|
||||
(LastSocketError() == EWOULDBLOCK ||
|
||||
LastSocketError() == EINTR ||
|
||||
@ -160,10 +161,19 @@ int recvUdpSocket(SOCKET s, char* buffer, int size, int useSelect) {
|
||||
// Return 0 for timeout
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// We may receive an error due to a previous ICMP Port Unreachable error received
|
||||
// by this socket. We want to ignore those and continue reading. If the remote party
|
||||
// is really dead, ENet or TCP connection failures will trigger connection teardown.
|
||||
#if defined(LC_WINDOWS)
|
||||
} while (err < 0 && LastSocketError() == WSAECONNRESET);
|
||||
#else
|
||||
} while (err < 0 && LastSocketError() == ECONNREFUSED);
|
||||
#endif
|
||||
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
void closeSocket(SOCKET s) {
|
||||
#if defined(LC_WINDOWS)
|
||||
|
Loading…
x
Reference in New Issue
Block a user