From 4d3dffacb4fe66ce10ac3caa6ef5f8daedd1f25c Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sat, 27 Jan 2024 21:29:25 +0100 Subject: [PATCH] scan earlier for dead Ethernet connections --- EthernetInterface.cpp | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/EthernetInterface.cpp b/EthernetInterface.cpp index 613c04e..6d440dd 100644 --- a/EthernetInterface.cpp +++ b/EthernetInterface.cpp @@ -238,29 +238,26 @@ void EthernetInterface::loop2() { // check for incoming data from all possible clients for (byte socket = 0; socket < MAX_SOCK_NUM; socket++) { - if (clients[socket]) { + if (clients[socket]) { + if (!clients[socket].connected()) { // stop any clients which disconnect + CommandDistributor::forget(socket); + clients[socket].stop(); + //if (Diag::ETHERNET) + DIAG(F("Ethernet: disconnect %d "), socket); + } - int available=clients[socket].available(); - if (available > 0) { - if (Diag::ETHERNET) DIAG(F("Ethernet: available socket=%d,avail=%d"), socket, available); - // read bytes from a client - int count = clients[socket].read(buffer, MAX_ETH_BUFFER); - buffer[count] = '\0'; // terminate the string properly - if (Diag::ETHERNET) DIAG(F(",count=%d:%e"), socket,buffer); - // execute with data going directly back - CommandDistributor::parse(socket,buffer,outboundRing); - return; // limit the amount of processing that takes place within 1 loop() cycle. - } - } - } - - // stop any clients which disconnect - for (int socket = 0; socket 0) { + if (Diag::ETHERNET) DIAG(F("Ethernet: available socket=%d,avail=%d"), socket, available); + // read bytes from a client + int count = clients[socket].read(buffer, MAX_ETH_BUFFER); + buffer[count] = '\0'; // terminate the string properly + if (Diag::ETHERNET) DIAG(F(",count=%d:%e"), socket,buffer); + // execute with data going directly back + CommandDistributor::parse(socket,buffer,outboundRing); + return; // limit the amount of processing that takes place within 1 loop() cycle. + } + } } WiThrottle::loop(outboundRing);