From 39beba60b13bc9b47185ea40c5500cc2da8f9f38 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Tue, 21 May 2019 17:23:01 -0400 Subject: [PATCH] Don't query closed sock --- src/TinyGsmClientSaraR4.h | 8 ++++++-- src/TinyGsmClientUBLOX.h | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index 6a4e55e..49eaf2a 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -590,6 +590,8 @@ protected: } size_t modemGetAvailable(uint8_t mux) { + // Querying a closed socket gives an error "operation not allowed" + if (!sockets[mux]->sock_connected) return 0; sendAT(GF("+USORD="), mux, ",0"); size_t result = 0; uint8_t res = waitResponse(GF(GSM_NL "+USORD:")); @@ -608,6 +610,8 @@ protected: } bool modemGetConnected(uint8_t mux) { + // Querying a closed socket gives an error "operation not allowed" + if (!sockets[mux]->sock_connected) return false; sendAT(GF("+USOCTL="), mux, ",10"); uint8_t res = waitResponse(GF(GSM_NL "+USOCTL:")); if (res != 1) @@ -683,14 +687,14 @@ TINY_GSM_MODEM_STREAM_UTILITIES() sockets[mux]->sock_available = len; } data = ""; - DBG("### Got Data:", len, "on", mux); + DBG("### URC Data Received:", len, "on", mux); } else if (data.endsWith(GF(GSM_NL "+UUSOCL:"))) { int mux = stream.readStringUntil('\n').toInt(); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->sock_connected = false; } data = ""; - DBG("### Closed: ", mux); + DBG("### URC Sock Closed:", mux); } } } while (millis() - startMillis < timeout_ms); diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index e1ca4d7..0d60e13 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -596,6 +596,8 @@ protected: } size_t modemGetAvailable(uint8_t mux) { + // Querying a closed socket gives an error "operation not allowed" + if (!sockets[mux]->sock_connected) return 0; sendAT(GF("+USORD="), mux, ",0"); size_t result = 0; uint8_t res = waitResponse(GF(GSM_NL "+USORD:")); @@ -614,6 +616,8 @@ protected: } bool modemGetConnected(uint8_t mux) { + // Querying a closed socket gives an error "operation not allowed" + if (!sockets[mux]->sock_connected) return false; sendAT(GF("+USOCTL="), mux, ",10"); uint8_t res = waitResponse(GF(GSM_NL "+USOCTL:")); if (res != 1) @@ -689,14 +693,14 @@ TINY_GSM_MODEM_STREAM_UTILITIES() sockets[mux]->sock_available = len; } data = ""; - DBG("### Got Data:", len, "on", mux); + DBG("### URC Data Received:", len, "on", mux); } else if (data.endsWith(GF(GSM_NL "+UUSOCL:"))) { int mux = stream.readStringUntil('\n').toInt(); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->sock_connected = false; } data = ""; - DBG("### Closed: ", mux); + DBG("### URC Sock Closed: ", mux); } } } while (millis() - startMillis < timeout_ms);