@@ -307,67 +307,15 @@ void ESP8266WebServer::send(int code, const String& content_type, const String&
307
307
}
308
308
309
309
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 ());
323
311
}
324
312
325
313
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));
351
315
}
352
316
353
317
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);
371
319
}
372
320
373
321
0 commit comments