Skip to content

Commit 2f5b3c0

Browse files
MaValkime-no-dev
authored andcommitted
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.
1 parent 1fe3ee8 commit 2f5b3c0

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

Diff for: libraries/WebServer/src/Parsing.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,14 @@ void WebServer::_uploadWriteByte(uint8_t b){
359359
_currentUpload->buf[_currentUpload->currentSize++] = b;
360360
}
361361

362-
uint8_t WebServer::_uploadReadByte(WiFiClient& client){
362+
int WebServer::_uploadReadByte(WiFiClient& client){
363363
int res = client.read();
364364
if(res == -1){
365365
while(!client.available() && client.connected())
366366
delay(2);
367367
res = client.read();
368368
}
369-
return (uint8_t)res;
369+
return res;
370370
}
371371

372372
bool WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
@@ -477,27 +477,28 @@ bool WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
477477
if(_currentHandler && _currentHandler->canUpload(_currentUri))
478478
_currentHandler->upload(*this, _currentUri, *_currentUpload);
479479
_currentUpload->status = UPLOAD_FILE_WRITE;
480-
uint8_t argByte = _uploadReadByte(client);
480+
int argByte;
481481
readfile:
482-
while(argByte != 0x0D){
483-
if (!client.connected()) return _parseFormUploadAborted();
484-
_uploadWriteByte(argByte);
482+
483+
do{
485484
argByte = _uploadReadByte(client);
486-
}
485+
if(argByte < 0) return _parseFormUploadAborted();
486+
_uploadWriteByte(argByte);
487+
}while(argByte != 0x0D);
487488

488489
argByte = _uploadReadByte(client);
489-
if (!client.connected()) return _parseFormUploadAborted();
490+
if(argByte < 0) return _parseFormUploadAborted();
490491
if (argByte == 0x0A){
491492
argByte = _uploadReadByte(client);
492-
if (!client.connected()) return _parseFormUploadAborted();
493+
if(argByte < 0) return _parseFormUploadAborted();
493494
if ((char)argByte != '-'){
494495
//continue reading the file
495496
_uploadWriteByte(0x0D);
496497
_uploadWriteByte(0x0A);
497498
goto readfile;
498499
} else {
499500
argByte = _uploadReadByte(client);
500-
if (!client.connected()) return _parseFormUploadAborted();
501+
if(argByte < 0) return _parseFormUploadAborted();
501502
if ((char)argByte != '-'){
502503
//continue reading the file
503504
_uploadWriteByte(0x0D);

Diff for: libraries/WebServer/src/WebServer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class WebServer
147147
bool _parseForm(WiFiClient& client, String boundary, uint32_t len);
148148
bool _parseFormUploadAborted();
149149
void _uploadWriteByte(uint8_t b);
150-
uint8_t _uploadReadByte(WiFiClient& client);
150+
int _uploadReadByte(WiFiClient& client);
151151
void _prepareHeader(String& response, int code, const char* content_type, size_t contentLength);
152152
bool _collectHeader(const char* headerName, const char* headerValue);
153153

0 commit comments

Comments
 (0)