Skip to content

Commit

Permalink
scan earlier for dead Ethernet connections
Browse files Browse the repository at this point in the history
  • Loading branch information
habazut committed Jan 27, 2024
1 parent 08c89f7 commit 4d3dffa
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions EthernetInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MAX_SOCK_NUM; socket++) {
if (clients[socket] && !clients[socket].connected()) {
clients[socket].stop();
CommandDistributor::forget(socket);
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.
}
}
}

WiThrottle::loop(outboundRing);
Expand Down

0 comments on commit 4d3dffa

Please sign in to comment.