From fe205d838d35b666ea0da9a437921b23b17e9c3d Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 28 Apr 2021 17:04:44 -0500 Subject: [PATCH] Don't check for errors from sendto() in the ping threads --- src/AudioStream.c | 12 +++++------- src/VideoStream.c | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/AudioStream.c b/src/AudioStream.c index e082b82..d3efd5f 100644 --- a/src/AudioStream.c +++ b/src/AudioStream.c @@ -44,19 +44,17 @@ static void UdpPingThreadProc(void* context) { // Ping in ASCII char pingData[] = { 0x50, 0x49, 0x4E, 0x47 }; LC_SOCKADDR saddr; - SOCK_RET err; memcpy(&saddr, &RemoteAddr, sizeof(saddr)); SET_PORT(&saddr, RTP_PORT); // Send PING every 500 milliseconds while (!PltIsThreadInterrupted(&udpPingThread)) { - err = sendto(rtpSocket, pingData, sizeof(pingData), 0, (struct sockaddr*)&saddr, RemoteAddrLen); - if (err != sizeof(pingData)) { - Limelog("Audio Ping: sendto() failed: %d\n", (int)LastSocketError()); - ListenerCallbacks.connectionTerminated(LastSocketFail()); - return; - } + // We do not check for errors here. Socket errors will be handled + // on the read-side in ReceiveThreadProc(). This avoids potential + // issues related to receiving ICMP port unreachable messages due + // to sending a packet prior to the host PC binding to that port. + sendto(rtpSocket, pingData, sizeof(pingData), 0, (struct sockaddr*)&saddr, RemoteAddrLen); if (firstReceiveTime == 0 && isSocketReadable(rtpSocket)) { // Remember the time when we got our first incoming audio packet. diff --git a/src/VideoStream.c b/src/VideoStream.c index d3e11e3..4d228b9 100644 --- a/src/VideoStream.c +++ b/src/VideoStream.c @@ -49,18 +49,16 @@ void destroyVideoStream(void) { static void UdpPingThreadProc(void* context) { char pingData[] = { 0x50, 0x49, 0x4E, 0x47 }; LC_SOCKADDR saddr; - SOCK_RET err; memcpy(&saddr, &RemoteAddr, sizeof(saddr)); SET_PORT(&saddr, RTP_PORT); while (!PltIsThreadInterrupted(&udpPingThread)) { - err = sendto(rtpSocket, pingData, sizeof(pingData), 0, (struct sockaddr*)&saddr, RemoteAddrLen); - if (err != sizeof(pingData)) { - Limelog("Video Ping: send() failed: %d\n", (int)LastSocketError()); - ListenerCallbacks.connectionTerminated(LastSocketFail()); - return; - } + // We do not check for errors here. Socket errors will be handled + // on the read-side in ReceiveThreadProc(). This avoids potential + // issues related to receiving ICMP port unreachable messages due + // to sending a packet prior to the host PC binding to that port. + sendto(rtpSocket, pingData, sizeof(pingData), 0, (struct sockaddr*)&saddr, RemoteAddrLen); PltSleepMsInterruptible(&udpPingThread, 500); }