1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-27 21:16:50 +03:00

Improvements to ESP8266WebServer::sendContent

Now makes only one call to .c_str() and using pointer tracking, rather that recalculating offset within the sending loop, to manage data window.

Moved invariant code out of the sending loop body.
This commit is contained in:
timw1971 2015-08-08 11:48:18 +01:00
parent cd69be7f8f
commit 15991fb35a

View File

@ -178,17 +178,18 @@ void ESP8266WebServer::send(int code, const String& content_type, const String&
} }
void ESP8266WebServer::sendContent(const String& content) { void ESP8266WebServer::sendContent(const String& content) {
const size_t unit_size = HTTP_DOWNLOAD_UNIT_SIZE;
size_t size_to_send = content.length(); size_t size_to_send = content.length();
size_t size_sent = 0; const char* send_start = content.c_str();
while(size_to_send) {
const size_t unit_size = HTTP_DOWNLOAD_UNIT_SIZE; while (size_to_send) {
size_t will_send = (size_to_send < unit_size) ? size_to_send : unit_size; size_t will_send = (size_to_send < unit_size) ? size_to_send : unit_size;
size_t sent = _currentClient.write(content.c_str() + size_sent, will_send); size_t sent = _currentClient.write(send_start, will_send);
size_to_send -= sent;
size_sent += sent;
if (sent == 0) { if (sent == 0) {
break; break;
} }
size_to_send -= sent;
send_start += sent;
} }
} }