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

Compare commits

..

5 Commits

Author SHA1 Message Date
Harald Barth
6cdde5d3c6 github tag 2024-01-28 01:47:28 +01:00
Harald Barth
60fb30c0a7 set ethernet client to NULL when done with it 2024-01-28 01:47:05 +01:00
Harald Barth
dd5ab6c7fa github tag 2024-01-27 21:30:20 +01:00
Harald Barth
4d3dffacb4 scan earlier for dead Ethernet connections 2024-01-27 21:29:25 +01:00
Harald Barth
08c89f743f make Ethernet socket array insert more fool proof 2024-01-27 21:12:09 +01:00
2 changed files with 38 additions and 36 deletions

View File

@ -213,22 +213,25 @@ void EthernetInterface::loop2() {
if (client)
{
byte socket;
for (socket = 0; socket < MAX_SOCK_NUM; socket++)
{
if (clients[socket]) {
if (clients[socket] == client)
bool sockfound = false;
for (socket = 0; socket < MAX_SOCK_NUM; socket++) {
if (clients[socket] && (clients[socket] == client)) {
sockfound = true;
if (Diag::ETHERNET) DIAG(F("Ethernet: Old client socket %d"),socket);
break;
}
else //if (!clients[socket])
{
if (Diag::ETHERNET) DIAG(F("Ethernet: New client "));
}
if (!sockfound) { // new client
for (socket = 0; socket < MAX_SOCK_NUM; socket++) {
if (!clients[socket]) {
// On accept() the EthernetServer doesn't track the client anymore
// so we store it in our client array
if (Diag::ETHERNET) DIAG(F("Socket %d"),socket);
clients[socket] = client;
if (Diag::ETHERNET) DIAG(F("Ethernet: New client socket %d"),socket);
break;
}
}
}
if (socket==MAX_SOCK_NUM) DIAG(F("new Ethernet OVERFLOW"));
}
@ -236,6 +239,14 @@ void EthernetInterface::loop2() {
for (byte socket = 0; socket < MAX_SOCK_NUM; socket++)
{
if (clients[socket]) {
if (!clients[socket].connected()) { // stop any clients which disconnect
CommandDistributor::forget(socket);
clients[socket].stop();
clients[socket]=NULL;
//if (Diag::ETHERNET)
DIAG(F("Ethernet: disconnect %d "), socket);
return; // Trick: So that we do not continue in this loop with client that is NULL
}
int available=clients[socket].available();
if (available > 0) {
@ -251,15 +262,6 @@ void EthernetInterface::loop2() {
}
}
// 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);
}
}
WiThrottle::loop(outboundRing);
// handle at most 1 outbound transmission

View File

@ -1 +1 @@
#define GITHUB_SHA "devel-202401202116Z"
#define GITHUB_SHA "devel-stm32EC 202401280047Z"