@@ -402,26 +402,30 @@ bool safeReadStringUntil(Stream &input, String &str, char terminator, unsigned i
402
402
403
403
do {
404
404
// read character
405
- c = input.read ();
406
- if (c >= 0 ) {
407
- // found terminator, we're ok
408
- if (c == terminator) {
409
- return (true );
410
- }
411
- // found character, add to string
412
- else {
413
- str += char (c);
414
- // string at max size?
415
- if (str.length () >= maxSize) {
416
- addLog (LOG_LEVEL_ERROR, F (" Not enough bufferspace to read all input data!" ));
417
- return (false );
418
- }
419
- }
420
- }
421
- // We must run the backgroundtasks every now and then.
422
- if (timeOutReached (backgroundtasks_timer)) {
423
- backgroundtasks_timer += 10 ;
424
- backgroundtasks ();
405
+ if (input.available ()) {
406
+ c = input.read ();
407
+ if (c >= 0 ) {
408
+ // found terminator, we're ok
409
+ if (c == terminator) {
410
+ return (true );
411
+ }
412
+ // found character, add to string
413
+ else {
414
+ str += char (c);
415
+ // string at max size?
416
+ if (str.length () >= maxSize) {
417
+ addLog (LOG_LEVEL_ERROR, F (" Not enough bufferspace to read all input data!" ));
418
+ return (false );
419
+ }
420
+ }
421
+ }
422
+ // We must run the backgroundtasks every now and then.
423
+ if (timeOutReached (backgroundtasks_timer)) {
424
+ backgroundtasks_timer += 10 ;
425
+ backgroundtasks ();
426
+ } else {
427
+ yield ();
428
+ }
425
429
} else {
426
430
yield ();
427
431
}
@@ -621,6 +625,11 @@ bool try_connect_host(int controller_number, WiFiClient& client, ControllerSetti
621
625
// See: https://github.com/esp8266/Arduino/pull/5113
622
626
// https://github.com/esp8266/Arduino/pull/1829
623
627
bool client_available (WiFiClient& client) {
628
+ #ifdef ESP32
629
+ yield ();
630
+ #else
631
+ esp_yield (); // Could be called from events
632
+ #endif
624
633
return client.available () || client.connected ();
625
634
}
626
635
@@ -631,7 +640,7 @@ bool send_via_http(const String& logIdentifier, WiFiClient& client, const String
631
640
632
641
if (must_check_reply) {
633
642
unsigned long timer = millis () + 200 ;
634
- while (!client. available ( )) {
643
+ while (!client_available (client )) {
635
644
if (timeOutReached (timer)) return false ;
636
645
delay (1 );
637
646
}
0 commit comments