Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7e8993f

Browse filesBrowse files
authored
Speed up upload by a factor of 17 (espressif#4787)
* Speed up upload by a factor of 17 Uploads are very slow because of an unnecessary "client.connected()" check in _uploadReadByte(). Here is what happens: client.connected() is called for every byte read. WiFiClient::connected() calls recv(fd(), &dummy, 0, MSG_DONTWAIT); which takes a relatively long time, so the optimized path of returning a buffered byte via client.read() is effectively nullified. Removing the one line changed the upload speed for a 2 MB file (discarding the received data) from 22 KB/sec (before) to 367 KB/sec (after). The change is safe in the face of disconnects because client.read(), when it no longer has buffered data, calls (WiFiClient) fillBuffer(), which calls recv(), so the disconnection will be detected in due course. * Move disconnect check into the timeout loop
1 parent 15bae92 commit 7e8993f
Copy full SHA for 7e8993f

File tree

Expand file treeCollapse file tree

1 file changed

+1
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+1
-1
lines changed

‎libraries/WebServer/src/Parsing.cpp

Copy file name to clipboardExpand all lines: libraries/WebServer/src/Parsing.cpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,14 @@ void WebServer::_uploadWriteByte(uint8_t b){
303303
}
304304

305305
int WebServer::_uploadReadByte(WiFiClient& client){
306-
if (!client.connected()) return -1;
307306
int res = client.read();
308307
if(res < 0) {
309308
// keep trying until you either read a valid byte or timeout
310309
unsigned long startMillis = millis();
311310
long timeoutIntervalMillis = client.getTimeout();
312311
boolean timedOut = false;
313312
for(;;) {
313+
if (!client.connected()) return -1;
314314
// loosely modeled after blinkWithoutDelay pattern
315315
while(!timedOut && !client.available() && client.connected()){
316316
delay(2);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.