@@ -276,56 +276,49 @@ void ESP8266WebServer::handleClient() {
276
276
_statusChange = millis ();
277
277
}
278
278
279
- if (!_currentClient.connected ()) {
280
- _currentClient = WiFiClient ();
281
- _currentStatus = HC_NONE;
282
- _currentUpload.reset ();
283
- return ;
284
- }
285
-
286
- // Wait for data from client to become available
287
- if (_currentStatus == HC_WAIT_READ) {
288
- if (!_currentClient.available ()) {
289
- if (millis () - _statusChange > HTTP_MAX_DATA_WAIT) {
290
- _currentClient = WiFiClient ();
291
- _currentStatus = HC_NONE;
292
- _currentUpload.reset ();
279
+ bool keepCurrentClient = false ;
280
+ bool callYield = false ;
281
+
282
+ if (_currentClient.connected ()) {
283
+ switch (_currentStatus) {
284
+ case HC_WAIT_READ:
285
+ // Wait for data from client to become available
286
+ if (_currentClient.available ()) {
287
+ if (_parseRequest (_currentClient)) {
288
+ _currentClient.setTimeout (HTTP_MAX_SEND_WAIT);
289
+ _contentLength = CONTENT_LENGTH_NOT_SET;
290
+ _handleRequest ();
291
+
292
+ if (_currentClient.connected ()) {
293
+ _currentStatus = HC_WAIT_CLOSE;
294
+ _statusChange = millis ();
295
+ keepCurrentClient = true ;
296
+ }
297
+ }
298
+ } else { // !_currentClient.available()
299
+ if (millis () - _statusChange <= HTTP_MAX_DATA_WAIT) {
300
+ keepCurrentClient = true ;
301
+ }
302
+ callYield = true ;
303
+ }
304
+ break ;
305
+ case HC_WAIT_CLOSE:
306
+ // Wait for client to close the connection
307
+ if (millis () - _statusChange <= HTTP_MAX_CLOSE_WAIT) {
308
+ keepCurrentClient = true ;
309
+ callYield = true ;
293
310
}
294
- yield ();
295
- return ;
296
311
}
312
+ }
297
313
298
- if (!_parseRequest (_currentClient)) {
299
- _currentClient = WiFiClient ();
300
- _currentStatus = HC_NONE;
301
- _currentUpload.reset ();
302
- return ;
303
- }
304
- _currentClient.setTimeout (HTTP_MAX_SEND_WAIT);
305
- _contentLength = CONTENT_LENGTH_NOT_SET;
306
- _handleRequest ();
307
-
308
- if (!_currentClient.connected ()) {
309
- _currentClient = WiFiClient ();
310
- _currentStatus = HC_NONE;
311
- _currentUpload.reset ();
312
- return ;
313
- } else {
314
- _currentStatus = HC_WAIT_CLOSE;
315
- _statusChange = millis ();
316
- return ;
317
- }
314
+ if (!keepCurrentClient) {
315
+ _currentClient = WiFiClient ();
316
+ _currentStatus = HC_NONE;
317
+ _currentUpload.reset ();
318
318
}
319
319
320
- if (_currentStatus == HC_WAIT_CLOSE) {
321
- if (millis () - _statusChange > HTTP_MAX_CLOSE_WAIT) {
322
- _currentClient = WiFiClient ();
323
- _currentStatus = HC_NONE;
324
- _currentUpload.reset ();
325
- } else {
326
- yield ();
327
- return ;
328
- }
320
+ if (callYield) {
321
+ yield ();
329
322
}
330
323
}
331
324
0 commit comments