1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-05-06 18:19:16 +03:00

minimize number of exit paths in ESP8266WebServer::handleClient (#2557)

This commit is contained in:
Christian Schuster 2017-10-17 22:08:50 +02:00 committed by Ivan Grokhotkov
parent 2fbc619569
commit e71ec77a00

View File

@ -276,56 +276,49 @@ void ESP8266WebServer::handleClient() {
_statusChange = millis(); _statusChange = millis();
} }
if (!_currentClient.connected()) { bool keepCurrentClient = false;
_currentClient = WiFiClient(); bool callYield = false;
_currentStatus = HC_NONE;
_currentUpload.reset();
return;
}
if (_currentClient.connected()) {
switch (_currentStatus) {
case HC_WAIT_READ:
// Wait for data from client to become available // Wait for data from client to become available
if (_currentStatus == HC_WAIT_READ) { if (_currentClient.available()) {
if (!_currentClient.available()) { if (_parseRequest(_currentClient)) {
if (millis() - _statusChange > HTTP_MAX_DATA_WAIT) {
_currentClient = WiFiClient();
_currentStatus = HC_NONE;
_currentUpload.reset();
}
yield();
return;
}
if (!_parseRequest(_currentClient)) {
_currentClient = WiFiClient();
_currentStatus = HC_NONE;
_currentUpload.reset();
return;
}
_currentClient.setTimeout(HTTP_MAX_SEND_WAIT); _currentClient.setTimeout(HTTP_MAX_SEND_WAIT);
_contentLength = CONTENT_LENGTH_NOT_SET; _contentLength = CONTENT_LENGTH_NOT_SET;
_handleRequest(); _handleRequest();
if (!_currentClient.connected()) { if (_currentClient.connected()) {
_currentClient = WiFiClient();
_currentStatus = HC_NONE;
_currentUpload.reset();
return;
} else {
_currentStatus = HC_WAIT_CLOSE; _currentStatus = HC_WAIT_CLOSE;
_statusChange = millis(); _statusChange = millis();
return; keepCurrentClient = true;
}
}
} else { // !_currentClient.available()
if (millis() - _statusChange <= HTTP_MAX_DATA_WAIT) {
keepCurrentClient = true;
}
callYield = true;
}
break;
case HC_WAIT_CLOSE:
// Wait for client to close the connection
if (millis() - _statusChange <= HTTP_MAX_CLOSE_WAIT) {
keepCurrentClient = true;
callYield = true;
}
} }
} }
if (_currentStatus == HC_WAIT_CLOSE) { if (!keepCurrentClient) {
if (millis() - _statusChange > HTTP_MAX_CLOSE_WAIT) {
_currentClient = WiFiClient(); _currentClient = WiFiClient();
_currentStatus = HC_NONE; _currentStatus = HC_NONE;
_currentUpload.reset(); _currentUpload.reset();
} else {
yield();
return;
} }
if (callYield) {
yield();
} }
} }