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

Cleaner purge after error or connect fail

This commit is contained in:
Asbelos 2020-10-27 12:33:01 +00:00
parent 138851f45f
commit a65ca0b704
2 changed files with 18 additions and 21 deletions

View File

@ -127,13 +127,10 @@ WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() {
break; break;
} }
if (ch=='E') { // ERROR if (ch=='E' || ch=='l') { // ERROR or "link is not valid"
if (pendingCipsend) { if (clientPendingCIPSEND>=0) {
// A CIPSEND was errored... just toss it away // A CIPSEND was errored... just toss it away
if (Diag::WIFI) DIAG(F("Wifi: drop previous CIPSEND\n")); purgeCurrentCIPSEND();
for (int i=0;i<=currentReplySize;i++) outboundRing->read();
clientPendingCIPSEND=-1;
pendingCipsend=false;
} }
loopState=SKIPTOEND; loopState=SKIPTOEND;
break; break;
@ -208,19 +205,10 @@ WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() {
loopState=(ch==',') ? GOT_CLIENT_ID2: SKIPTOEND; loopState=(ch==',') ? GOT_CLIENT_ID2: SKIPTOEND;
break; break;
case GOT_CLIENT_ID2: // got "x," before CLOSE or CONNECTED case GOT_CLIENT_ID2: // got "x,"
loopState=(ch=='C') ? GOT_CLIENT_ID3: SKIPTOEND; if (ch=='C') {
break; // got "x C" before CLOSE or CONNECTED, or CONNECT FAILED
if (runningClientId==clientPendingCIPSEND) purgeCurrentCIPSEND();
case GOT_CLIENT_ID3: // got "x C" before CLOSE or CONNECTED (which is ignored)
if(ch=='L') {
// CLOSE
if (runningClientId==clientPendingCIPSEND) {
// clear the outbound for this client
for (int i=0;i<=currentReplySize;i++) outboundRing->read();
clientPendingCIPSEND=-1;
pendingCipsend=false;
}
} }
loopState=SKIPTOEND; loopState=SKIPTOEND;
break; break;
@ -232,3 +220,11 @@ WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() {
} // available } // available
return (loopState==ANYTHING) ? INBOUND_IDLE: INBOUND_BUSY; return (loopState==ANYTHING) ? INBOUND_IDLE: INBOUND_BUSY;
} }
void WifiInboundHandler::purgeCurrentCIPSEND() {
// A CIPSEND was sent but errored... or the client closed just toss it away
if (Diag::WIFI) DIAG(F("Wifi: DROPPING CIPSEND=%d,%d\n"),clientPendingCIPSEND,currentReplySize);
for (int i=0;i<=currentReplySize;i++) outboundRing->read();
pendingCipsend=false;
clientPendingCIPSEND=-1;
}

View File

@ -44,6 +44,7 @@ class WifiInboundHandler {
WifiInboundHandler(Stream * ESStream); WifiInboundHandler(Stream * ESStream);
void loop1(); void loop1();
INBOUND_STATE loop2(); INBOUND_STATE loop2();
void purgeCurrentCIPSEND();
Stream * wifiStream; Stream * wifiStream;
static const int INBOUND_RING = 512; static const int INBOUND_RING = 512;