1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Merge pull request #672 from timw1971/patch-1

Improvements to ESP8266WebServer::sendContent
This commit is contained in:
Ivan Grokhotkov 2015-08-10 17:36:48 +03:00
commit c5d7aead8e

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) {
size_t size_to_send = content.length();
size_t size_sent = 0;
while(size_to_send) {
const size_t unit_size = HTTP_DOWNLOAD_UNIT_SIZE; const size_t unit_size = HTTP_DOWNLOAD_UNIT_SIZE;
size_t size_to_send = content.length();
const char* send_start = content.c_str();
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;
} }
} }