File tree 2 files changed +34
-8
lines changed
2 files changed +34
-8
lines changed Original file line number Diff line number Diff line change @@ -345,13 +345,41 @@ void WebServer::_uploadWriteByte(uint8_t b) {
345
345
346
346
int WebServer::_uploadReadByte (NetworkClient &client) {
347
347
int res = client.read ();
348
-
348
+
349
349
if (res < 0 ) {
350
- while (!client.available () && client.connected ()) {
351
- delay (2 );
352
- }
350
+ // keep trying until you either read a valid byte or timeout
351
+ const unsigned long startMillis = millis ();
352
+ const long timeoutIntervalMillis = client.getTimeout ();
353
+ bool timedOut = false ;
354
+ for (;;) {
355
+ if (!client.connected ()) return -1 ;
356
+ // loosely modeled after blinkWithoutDelay pattern
357
+ while (!timedOut && !client.available () && client.connected ()){
358
+ delay (2 );
359
+ timedOut = (millis () - startMillis) >= timeoutIntervalMillis;
360
+ }
353
361
354
- res = client.read ();
362
+ res = client.read ();
363
+ if (res >= 0 ) {
364
+ return res; // exit on a valid read
365
+ }
366
+ // NOTE: it is possible to get here and have all of the following
367
+ // assertions hold true
368
+ //
369
+ // -- client.available() > 0
370
+ // -- client.connected == true
371
+ // -- res == -1
372
+ //
373
+ // a simple retry strategy overcomes this which is to say the
374
+ // assertion is not permanent, but the reason that this works
375
+ // is elusive, and possibly indicative of a more subtle underlying
376
+ // issue
377
+
378
+ timedOut = (millis () - startMillis) >= timeoutIntervalMillis;
379
+ if (timedOut) {
380
+ return res; // exit on a timeout
381
+ }
382
+ }
355
383
}
356
384
357
385
return res;
Original file line number Diff line number Diff line change @@ -432,10 +432,8 @@ void WebServer::handleClient() {
432
432
case HC_WAIT_READ:
433
433
// Wait for data from client to become available
434
434
if (_currentClient.available ()) {
435
+ _currentClient.setTimeout (HTTP_MAX_SEND_WAIT); /* / 1000 removed, WifiClient setTimeout changed to ms */
435
436
if (_parseRequest (_currentClient)) {
436
- // because HTTP_MAX_SEND_WAIT is expressed in milliseconds,
437
- // it must be divided by 1000
438
- _currentClient.setTimeout (HTTP_MAX_SEND_WAIT); /* / 1000 removed, WifiClient setTimeout changed to ms */
439
437
_contentLength = CONTENT_LENGTH_NOT_SET;
440
438
_handleRequest ();
441
439
You can’t perform that action at this time.
0 commit comments