cope with race on available() vs read() found while looking at #838

1.2-legacy
Kevin Hester 2021-08-12 22:06:51 -07:00
rodzic 9f450cb1c5
commit a9f8080ee7
1 zmienionych plików z 5 dodań i 1 usunięć

Wyświetl plik

@ -26,7 +26,11 @@ int32_t StreamAPI::readStream()
return recentRx ? 5 : 250;
} else {
while (stream->available()) { // Currently we never want to block
uint8_t c = stream->read();
int cInt = stream->read();
if(cInt < 0)
break; // We ran out of characters (even though available said otherwise) - this can happen on rf52 adafruit arduino
uint8_t c = (uint8_t) cInt;
// Use the read pointer for a little state machine, first look for framing, then length bytes, then payload
size_t ptr = rxPtr;