Skip to content

Commit 0916654

Browse files
committed
TcpServer: Rework the client connection logic
1 parent 5c3bd53 commit 0916654

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

Firmware/RTK_Everywhere/TcpServer.ino

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -330,32 +330,33 @@ void tcpServerClientUpdate(uint8_t index)
330330
int spot;
331331

332332
// Determine if the client data structure is in use
333-
if (tcpServerClientConnected & (1 << index))
333+
while (tcpServerClientConnected & (1 << index))
334334
{
335-
// Data structure in use
335+
// The client data structure is in use
336336
// Check for a working TCP server client connection
337337
clientConnected = tcpServerClient[index]->connected();
338338
dataSent = ((millis() - tcpServerTimer) < TCP_SERVER_CLIENT_DATA_TIMEOUT) ||
339339
(tcpServerClientDataSent & (1 << index));
340-
if (clientConnected && dataSent)
340+
if ((clientConnected && dataSent) == false)
341341
{
342-
// Display this client connection
343-
if (PERIODIC_DISPLAY(PD_TCP_SERVER_DATA) && (!inMainMenu))
344-
{
345-
PERIODIC_CLEAR(PD_TCP_SERVER_DATA);
346-
systemPrintf("%s client %d connected to %s\r\n",
347-
tcpServerName, index,
348-
tcpServerClientIpAddress[index].toString().c_str());
349-
}
342+
// Broken connection, shutdown the TCP server client link
343+
tcpServerStopClient(index);
344+
break;
350345
}
351346

352-
// Shutdown the TCP server client link
353-
else
354-
tcpServerStopClient(index);
347+
// Periodically display this client connection
348+
if (PERIODIC_DISPLAY(PD_TCP_SERVER_DATA) && (!inMainMenu))
349+
{
350+
PERIODIC_CLEAR(PD_TCP_SERVER_DATA);
351+
systemPrintf("%s client %d connected to %s\r\n",
352+
tcpServerName, index,
353+
tcpServerClientIpAddress[index].toString().c_str());
354+
}
355+
break;
355356
}
356357

357-
// Determine if the client data structure is in use
358-
if (!(tcpServerClientConnected & (1 << index)))
358+
// Determine if the client data structure is not in use
359+
while ((tcpServerClientConnected & (1 << index)) == 0)
359360
{
360361
if(tcpServerClient[index] == nullptr)
361362
tcpServerClient[index] = new NetworkClient;
@@ -429,6 +430,7 @@ void tcpServerClientUpdate(uint8_t index)
429430
tcpServerClientConnected = tcpServerClientConnected | (1 << index);
430431
tcpServerClientDataSent = tcpServerClientDataSent | (1 << index);
431432
}
433+
break;
432434
}
433435
}
434436

0 commit comments

Comments
 (0)