Skip to content

Commit 0555fb6

Browse files
committed
NtripServer - gently absorb incoming traffic (to free TCP resources); break connection if write fails
1 parent ac6e0d3 commit 0555fb6

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

Firmware/RTK_Everywhere/NtripServer.ino

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,25 @@ void ntripServerProcessRTCM(int serverIndex, uint8_t incoming)
445445

446446
if (ntripServer->networkClient && ntripServer->networkClient->connected())
447447
{
448-
ntripServer->networkClient->write(incoming); // Send this byte to socket
449-
ntripServer->bytesSent = ntripServer->bytesSent + 1;
450-
ntripServer->rtcmBytesSent = ntripServer->rtcmBytesSent + 1;
451-
ntripServer->timer = millis();
452-
netOutgoingRTCM = true;
448+
if (ntripServer->networkClient->write(incoming) == 1) // Send this byte to socket
449+
{
450+
ntripServer->bytesSent = ntripServer->bytesSent + 1;
451+
ntripServer->rtcmBytesSent = ntripServer->rtcmBytesSent + 1;
452+
ntripServer->timer = millis();
453+
netOutgoingRTCM = true;
454+
if (ntripServer->networkClient->available())
455+
ntripServer->networkClient->read(); // Gently absorb any unwanted incoming traffic
456+
}
457+
// Failed to write the data
458+
else
459+
{
460+
// Done with this client connection
461+
if (!inMainMenu)
462+
systemPrintf("NTRIP Server %d breaking connection to %s\r\n", serverIndex,
463+
settings.ntripServer_CasterHost[serverIndex]);
464+
465+
ntripServerShutdown(serverIndex);
466+
}
453467
}
454468
}
455469

0 commit comments

Comments
 (0)