Ensure that ALL variants of read respect timeout

This commit is contained in:
Sara Damiano
2019-05-20 13:12:09 -04:00
parent b96c866bad
commit 7f7a7563cf
12 changed files with 27 additions and 17 deletions

View File

@@ -599,7 +599,8 @@ TINY_GSP_MODEM_STREAM_UTILITIES()
DBG("### Got: ", len, "->", sockets[mux]->rx.free());
}
while (len--) {
while (!stream.available()) { TINY_GSM_YIELD(); }
startMillis = millis();
while (!stream.available() && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); }
sockets[mux]->rx.put(stream.read());
}
if (len_orig > sockets[mux]->available()) { // TODO

View File

@@ -517,7 +517,8 @@ protected:
sockets[mux]->sock_available = len;
for (size_t i=0; i<len; i++) {
while (!stream.available()) { TINY_GSM_YIELD(); }
uint32_t startMillis = millis();
while (!stream.available() && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); }
char c = stream.read();
sockets[mux]->rx.put(c);
}

View File

@@ -421,7 +421,8 @@ TINY_GSP_MODEM_STREAM_UTILITIES()
DBG("### Got: ", len, "->", sockets[mux]->rx.free());
}
while (len--) {
while (!stream.available()) { TINY_GSM_YIELD(); }
startMillis = millis();
while (!stream.available() && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); }
sockets[mux]->rx.put(stream.read());
}
if (len_orig > sockets[mux]->available()) { // TODO

View File

@@ -520,7 +520,8 @@ TINY_GSP_MODEM_STREAM_UTILITIES()
DBG("### Got: ", len, "->", sockets[mux]->rx.free());
}
while (len--) {
while (!stream.available()) { TINY_GSM_YIELD(); }
uint32_t startMillis = millis();
while (!stream.available() && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); }
sockets[mux]->rx.put(stream.read());
}
if (len_orig > sockets[mux]->available()) { // TODO

View File

@@ -571,7 +571,8 @@ protected:
sockets[mux]->sock_available = len;
for (size_t i=0; i<len; i++) {
while (!stream.available()) { TINY_GSM_YIELD(); }
uint32_t startMillis = millis();
while (!stream.available() && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); }
char c = stream.read();
sockets[mux]->rx.put(c);
}

View File

@@ -591,7 +591,8 @@ protected:
sockets[mux]->sock_available = len;
for (size_t i=0; i<len; i++) {
while (!stream.available()) { TINY_GSM_YIELD(); }
uint32_t startMillis = millis();
while (!stream.available() && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); }
char c = stream.read();
sockets[mux]->rx.put(c);
}

View File

@@ -9,7 +9,7 @@
#ifndef TinyGsmClientSIM7000_h
#define TinyGsmClientSIM7000_h
#define TINY_GSM_DEBUG Serial
// #define TINY_GSM_DEBUG Serial
//#define TINY_GSM_USE_HEX
#if !defined(TINY_GSM_RX_BUFFER)
@@ -815,14 +815,15 @@ protected:
// 0 indicates that no data can be read.
for (size_t i=0; i<TinyGsmMin(len_confirmed, len_requested) ; i++) {
uint32_t startMillis = millis();
#ifdef TINY_GSM_USE_HEX
while (stream.available() < 2) { TINY_GSM_YIELD(); }
while (stream.available() < 2 && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); }
char buf[4] = { 0, };
buf[0] = stream.read();
buf[1] = stream.read();
char c = strtol(buf, NULL, 16);
#else
while (!stream.available()) { TINY_GSM_YIELD(); }
while (!stream.available() && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); }
char c = stream.read();
#endif
sockets[mux]->rx.put(c);

View File

@@ -743,14 +743,15 @@ protected:
// 0 indicates that no data can be read.
for (size_t i=0; i<TinyGsmMin(len_confirmed, len_requested) ; i++) {
uint32_t startMillis = millis();
#ifdef TINY_GSM_USE_HEX
while (stream.available() < 2) { TINY_GSM_YIELD(); }
while (stream.available() < 2 && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); }
char buf[4] = { 0, };
buf[0] = stream.read();
buf[1] = stream.read();
char c = strtol(buf, NULL, 16);
#else
while (!stream.available()) { TINY_GSM_YIELD(); }
while (!stream.available() && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); }
char c = stream.read();
#endif
sockets[mux]->rx.put(c);

View File

@@ -566,7 +566,6 @@ protected:
sockets[mux]->sock_connected = false;
return true;
}
bool success;
// These modems allow a faster "asynchronous" close
sendAT(GF("+USOCL="), mux, GF(",1"));
return 1 == waitResponse(120000L); // but it still can take up to 120s to get a response
@@ -602,7 +601,8 @@ protected:
streamSkipUntil('\"');
for (size_t i=0; i<len; i++) {
while (!stream.available()) { TINY_GSM_YIELD(); }
uint32_t startMillis = millis();
while (!stream.available() && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); }
char c = stream.read();
sockets[mux]->rx.put(c);
}

View File

@@ -541,7 +541,8 @@ protected:
streamSkipUntil(','); // Skip mux
size_t len = stream.readStringUntil('\n').toInt();
for (size_t i=0; i<len; i++) {
while (!stream.available()) { TINY_GSM_YIELD(); }
uint32_t startMillis = millis();
while (!stream.available() && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); }
char c = stream.read();
sockets[mux]->rx.put(c);
}

View File

@@ -587,7 +587,8 @@ protected:
streamSkipUntil('\"');
for (size_t i=0; i<len; i++) {
while (!stream.available()) { TINY_GSM_YIELD(); }
uint32_t startMillis = millis();
while (!stream.available() && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); }
char c = stream.read();
sockets[mux]->rx.put(c);
}

View File

@@ -103,7 +103,7 @@ public:
return sock_connected;
}
virtual int connect(const char *host, uint16_t port) {
return connect(host, port, 75000L);
return connect(host, port, 75);
}
virtual int connect(IPAddress ip, uint16_t port, int timeout_s) {
@@ -113,7 +113,7 @@ public:
return sock_connected;
}
virtual int connect(IPAddress ip, uint16_t port) {
return connect(ip, port, 75000L);
return connect(ip, port, 75);
}
virtual void stop() {