Functions _uploadReadByte and _parseForm were modified in order to (#1677)

speed up uploading data. Now there is no need to call time consuming
client.connected() method.
This commit is contained in:
MaValki 2018-07-25 17:37:15 +02:00 committed by Me No Dev
parent 1fe3ee87b6
commit 2f5b3c0c56
2 changed files with 12 additions and 11 deletions

View File

@ -359,14 +359,14 @@ void WebServer::_uploadWriteByte(uint8_t b){
_currentUpload->buf[_currentUpload->currentSize++] = b; _currentUpload->buf[_currentUpload->currentSize++] = b;
} }
uint8_t WebServer::_uploadReadByte(WiFiClient& client){ int WebServer::_uploadReadByte(WiFiClient& client){
int res = client.read(); int res = client.read();
if(res == -1){ if(res == -1){
while(!client.available() && client.connected()) while(!client.available() && client.connected())
delay(2); delay(2);
res = client.read(); res = client.read();
} }
return (uint8_t)res; return res;
} }
bool WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){ bool WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
@ -477,19 +477,20 @@ bool WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
if(_currentHandler && _currentHandler->canUpload(_currentUri)) if(_currentHandler && _currentHandler->canUpload(_currentUri))
_currentHandler->upload(*this, _currentUri, *_currentUpload); _currentHandler->upload(*this, _currentUri, *_currentUpload);
_currentUpload->status = UPLOAD_FILE_WRITE; _currentUpload->status = UPLOAD_FILE_WRITE;
uint8_t argByte = _uploadReadByte(client); int argByte;
readfile: readfile:
while(argByte != 0x0D){
if (!client.connected()) return _parseFormUploadAborted(); do{
_uploadWriteByte(argByte);
argByte = _uploadReadByte(client); argByte = _uploadReadByte(client);
} if(argByte < 0) return _parseFormUploadAborted();
_uploadWriteByte(argByte);
}while(argByte != 0x0D);
argByte = _uploadReadByte(client); argByte = _uploadReadByte(client);
if (!client.connected()) return _parseFormUploadAborted(); if(argByte < 0) return _parseFormUploadAborted();
if (argByte == 0x0A){ if (argByte == 0x0A){
argByte = _uploadReadByte(client); argByte = _uploadReadByte(client);
if (!client.connected()) return _parseFormUploadAborted(); if(argByte < 0) return _parseFormUploadAborted();
if ((char)argByte != '-'){ if ((char)argByte != '-'){
//continue reading the file //continue reading the file
_uploadWriteByte(0x0D); _uploadWriteByte(0x0D);
@ -497,7 +498,7 @@ readfile:
goto readfile; goto readfile;
} else { } else {
argByte = _uploadReadByte(client); argByte = _uploadReadByte(client);
if (!client.connected()) return _parseFormUploadAborted(); if(argByte < 0) return _parseFormUploadAborted();
if ((char)argByte != '-'){ if ((char)argByte != '-'){
//continue reading the file //continue reading the file
_uploadWriteByte(0x0D); _uploadWriteByte(0x0D);

View File

@ -147,7 +147,7 @@ protected:
bool _parseForm(WiFiClient& client, String boundary, uint32_t len); bool _parseForm(WiFiClient& client, String boundary, uint32_t len);
bool _parseFormUploadAborted(); bool _parseFormUploadAborted();
void _uploadWriteByte(uint8_t b); void _uploadWriteByte(uint8_t b);
uint8_t _uploadReadByte(WiFiClient& client); int _uploadReadByte(WiFiClient& client);
void _prepareHeader(String& response, int code, const char* content_type, size_t contentLength); void _prepareHeader(String& response, int code, const char* content_type, size_t contentLength);
bool _collectHeader(const char* headerName, const char* headerValue); bool _collectHeader(const char* headerName, const char* headerValue);