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

@@ -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);