Skip to content

Commit 2ebfed4

Browse files
committed
ESP8266WebServer: delegate writing to WiFiClient
1 parent 25962b2 commit 2ebfed4

File tree

1 file changed

+3
-55
lines changed

1 file changed

+3
-55
lines changed

libraries/ESP8266WebServer/src/ESP8266WebServer.cpp

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -307,67 +307,15 @@ void ESP8266WebServer::send(int code, const String& content_type, const String&
307307
}
308308

309309
void ESP8266WebServer::sendContent(const String& content) {
310-
const size_t unit_size = HTTP_DOWNLOAD_UNIT_SIZE;
311-
size_t size_to_send = content.length();
312-
const char* send_start = content.c_str();
313-
314-
while (size_to_send) {
315-
size_t will_send = (size_to_send < unit_size) ? size_to_send : unit_size;
316-
size_t sent = _currentClient.write(send_start, will_send);
317-
if (sent == 0) {
318-
break;
319-
}
320-
size_to_send -= sent;
321-
send_start += sent;
322-
}
310+
_currentClient.write(content.c_str(), content.length());
323311
}
324312

325313
void ESP8266WebServer::sendContent_P(PGM_P content) {
326-
char contentUnit[HTTP_DOWNLOAD_UNIT_SIZE + 1];
327-
328-
contentUnit[HTTP_DOWNLOAD_UNIT_SIZE] = '\0';
329-
330-
while (content != NULL) {
331-
size_t contentUnitLen;
332-
PGM_P contentNext;
333-
334-
// due to the memccpy signature, lots of casts are needed
335-
contentNext = (PGM_P)memccpy_P((void*)contentUnit, (PGM_VOID_P)content, 0, HTTP_DOWNLOAD_UNIT_SIZE);
336-
337-
if (contentNext == NULL) {
338-
// no terminator, more data available
339-
content += HTTP_DOWNLOAD_UNIT_SIZE;
340-
contentUnitLen = HTTP_DOWNLOAD_UNIT_SIZE;
341-
}
342-
else {
343-
// reached terminator. Do not send the terminator
344-
contentUnitLen = contentNext - contentUnit - 1;
345-
content = NULL;
346-
}
347-
348-
// write is so overloaded, had to use the cast to get it pick the right one
349-
_currentClient.write((const char*)contentUnit, contentUnitLen);
350-
}
314+
_currentClient.write_P(content, strlen_P(content));
351315
}
352316

353317
void ESP8266WebServer::sendContent_P(PGM_P content, size_t size) {
354-
char contentUnit[HTTP_DOWNLOAD_UNIT_SIZE + 1];
355-
contentUnit[HTTP_DOWNLOAD_UNIT_SIZE] = '\0';
356-
size_t remaining_size = size;
357-
358-
while (content != NULL && remaining_size > 0) {
359-
size_t contentUnitLen = HTTP_DOWNLOAD_UNIT_SIZE;
360-
361-
if (remaining_size < HTTP_DOWNLOAD_UNIT_SIZE) contentUnitLen = remaining_size;
362-
// due to the memcpy signature, lots of casts are needed
363-
memcpy_P((void*)contentUnit, (PGM_VOID_P)content, contentUnitLen);
364-
365-
content += contentUnitLen;
366-
remaining_size -= contentUnitLen;
367-
368-
// write is so overloaded, had to use the cast to get it pick the right one
369-
_currentClient.write((const char*)contentUnit, contentUnitLen);
370-
}
318+
_currentClient.write_P(content, size);
371319
}
372320

373321

0 commit comments

Comments
 (0)