Skip to content

Commit eb888e4

Browse files
committed
TcpServer: Handle client allocation failures
1 parent b7285c3 commit eb888e4

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

Firmware/RTK_Everywhere/TcpServer.ino

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,18 +452,29 @@ void tcpServerClientUpdate(uint8_t index)
452452
{
453453
// Data structure not in use
454454
if(tcpServerClient[index] == nullptr)
455+
{
455456
tcpServerClient[index] = new NetworkClient;
456457

457-
// Check for another TCP server client
458+
// Check for allocation failure
459+
if(tcpServerClient[index] == nullptr)
460+
{
461+
if (settings.debugTcpServer)
462+
Serial.printf("ERROR: Failed to allocate %s client!\r\n", tcpServerName);
463+
break;
464+
}
465+
}
466+
467+
// Check for another incoming TCP server client connection request
458468
*tcpServerClient[index] = tcpServer->accept();
459469

460470
// Exit if no TCP server client found
461471
if (!*tcpServerClient[index])
462472
break;
463473

464-
// TCP server client found
465-
// Start processing the new TCP server client connection
474+
// Get the remote IP address
466475
tcpServerClientIpAddress[index] = tcpServerClient[index]->remoteIP();
476+
477+
// Display the connection
467478
if ((settings.debugTcpServer || PERIODIC_DISPLAY(PD_TCP_SERVER_DATA)) && (!inMainMenu))
468479
systemPrintf("%s client %d connected to %s\r\n",
469480
tcpServerName, index,

0 commit comments

Comments
 (0)