1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-23 16:16:13 +01:00

make Ethernet socket array insert more fool proof

This commit is contained in:
Harald Barth 2024-01-27 21:12:09 +01:00
parent fdf6269477
commit 08c89f743f

View File

@ -213,21 +213,24 @@ void EthernetInterface::loop2() {
if (client) if (client)
{ {
byte socket; byte socket;
for (socket = 0; socket < MAX_SOCK_NUM; socket++) bool sockfound = false;
{ for (socket = 0; socket < MAX_SOCK_NUM; socket++) {
if (clients[socket]) { if (clients[socket] && (clients[socket] == client)) {
if (clients[socket] == client) sockfound = true;
break; if (Diag::ETHERNET) DIAG(F("Ethernet: Old client socket %d"),socket);
break;
} }
else //if (!clients[socket]) }
{ if (!sockfound) { // new client
if (Diag::ETHERNET) DIAG(F("Ethernet: New client ")); for (socket = 0; socket < MAX_SOCK_NUM; socket++) {
// On accept() the EthernetServer doesn't track the client anymore if (!clients[socket]) {
// so we store it in our client array // On accept() the EthernetServer doesn't track the client anymore
if (Diag::ETHERNET) DIAG(F("Socket %d"),socket); // so we store it in our client array
clients[socket] = client; clients[socket] = client;
break; if (Diag::ETHERNET) DIAG(F("Ethernet: New client socket %d"),socket);
break;
} }
}
} }
if (socket==MAX_SOCK_NUM) DIAG(F("new Ethernet OVERFLOW")); if (socket==MAX_SOCK_NUM) DIAG(F("new Ethernet OVERFLOW"));
} }