File tree Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -480,11 +480,31 @@ int NetworkClient::read(uint8_t *buf, size_t size) {
480
480
}
481
481
482
482
size_t NetworkClient::readBytes (char *buffer, size_t length) {
483
- int r = read ((uint8_t *)buffer, length);
484
- if (r < 0 ) {
485
- return 0 ;
483
+ size_t left = length, sofar = 0 ;
484
+ int r = 0 , to = millis () + _timeout;
485
+ while (left) {
486
+ r = read ((uint8_t *)buffer+sofar, left);
487
+ if (r < 0 ) {
488
+ // Error has occurred
489
+ break ;
490
+ }
491
+ if (r > 0 ) {
492
+ // We got some data
493
+ left -= r;
494
+ sofar += r;
495
+ to = millis () + _timeout;
496
+ } else {
497
+ // We got no data
498
+ if (millis () >= to) {
499
+ // We have waited for data enough
500
+ log_w (" Timeout waiting for data on fd %d" , fd ());
501
+ break ;
502
+ }
503
+ // Allow other tasks to run
504
+ delay (2 );
505
+ }
486
506
}
487
- return ( size_t )r ;
507
+ return sofar ;
488
508
}
489
509
490
510
int NetworkClient::peek () {
You can’t perform that action at this time.
0 commit comments