From a65ca0b704cffb3564fbf17aabb82d623a37c761 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Tue, 27 Oct 2020 12:33:01 +0000 Subject: [PATCH] Cleaner purge after error or connect fail --- WifiInboundHandler.cpp | 38 +++++++++++++++++--------------------- WifiInboundHandler.h | 1 + 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/WifiInboundHandler.cpp b/WifiInboundHandler.cpp index 00a682f..2463921 100644 --- a/WifiInboundHandler.cpp +++ b/WifiInboundHandler.cpp @@ -127,13 +127,10 @@ WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() { break; } - if (ch=='E') { // ERROR - if (pendingCipsend) { + if (ch=='E' || ch=='l') { // ERROR or "link is not valid" + if (clientPendingCIPSEND>=0) { // A CIPSEND was errored... just toss it away - if (Diag::WIFI) DIAG(F("Wifi: drop previous CIPSEND\n")); - for (int i=0;i<=currentReplySize;i++) outboundRing->read(); - clientPendingCIPSEND=-1; - pendingCipsend=false; + purgeCurrentCIPSEND(); } loopState=SKIPTOEND; break; @@ -208,22 +205,13 @@ WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() { loopState=(ch==',') ? GOT_CLIENT_ID2: SKIPTOEND; break; - case GOT_CLIENT_ID2: // got "x," before CLOSE or CONNECTED - loopState=(ch=='C') ? GOT_CLIENT_ID3: SKIPTOEND; + case GOT_CLIENT_ID2: // got "x," + if (ch=='C') { + // got "x C" before CLOSE or CONNECTED, or CONNECT FAILED + if (runningClientId==clientPendingCIPSEND) purgeCurrentCIPSEND(); + } + loopState=SKIPTOEND; break; - - 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; - break; case SKIPTOEND: // skipping for /n if (ch=='\n') loopState=ANYTHING; @@ -232,3 +220,11 @@ WifiInboundHandler::INBOUND_STATE WifiInboundHandler::loop2() { } // available 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; +} diff --git a/WifiInboundHandler.h b/WifiInboundHandler.h index 953b08d..1979565 100644 --- a/WifiInboundHandler.h +++ b/WifiInboundHandler.h @@ -44,6 +44,7 @@ class WifiInboundHandler { WifiInboundHandler(Stream * ESStream); void loop1(); INBOUND_STATE loop2(); + void purgeCurrentCIPSEND(); Stream * wifiStream; static const int INBOUND_RING = 512;