@@ -310,67 +310,15 @@ void ESP8266WebServer::send(int code, const String& content_type, const String&
310
310
}
311
311
312
312
void ESP8266WebServer::sendContent (const String& content) {
313
- const size_t unit_size = HTTP_DOWNLOAD_UNIT_SIZE;
314
- size_t size_to_send = content.length ();
315
- const char * send_start = content.c_str ();
316
-
317
- while (size_to_send) {
318
- size_t will_send = (size_to_send < unit_size) ? size_to_send : unit_size;
319
- size_t sent = _currentClient.write (send_start, will_send);
320
- if (sent == 0 ) {
321
- break ;
322
- }
323
- size_to_send -= sent;
324
- send_start += sent;
325
- }
313
+ _currentClient.write (content.c_str (), content.length ());
326
314
}
327
315
328
316
void ESP8266WebServer::sendContent_P (PGM_P content) {
329
- char contentUnit[HTTP_DOWNLOAD_UNIT_SIZE + 1 ];
330
-
331
- contentUnit[HTTP_DOWNLOAD_UNIT_SIZE] = ' \0 ' ;
332
-
333
- while (content != NULL ) {
334
- size_t contentUnitLen;
335
- PGM_P contentNext;
336
-
337
- // due to the memccpy signature, lots of casts are needed
338
- contentNext = (PGM_P)memccpy_P ((void *)contentUnit, (PGM_VOID_P)content, 0 , HTTP_DOWNLOAD_UNIT_SIZE);
339
-
340
- if (contentNext == NULL ) {
341
- // no terminator, more data available
342
- content += HTTP_DOWNLOAD_UNIT_SIZE;
343
- contentUnitLen = HTTP_DOWNLOAD_UNIT_SIZE;
344
- }
345
- else {
346
- // reached terminator. Do not send the terminator
347
- contentUnitLen = contentNext - contentUnit - 1 ;
348
- content = NULL ;
349
- }
350
-
351
- // write is so overloaded, had to use the cast to get it pick the right one
352
- _currentClient.write ((const char *)contentUnit, contentUnitLen);
353
- }
317
+ _currentClient.write_P (content, strlen_P (content));
354
318
}
355
319
356
320
void ESP8266WebServer::sendContent_P (PGM_P content, size_t size) {
357
- char contentUnit[HTTP_DOWNLOAD_UNIT_SIZE + 1 ];
358
- contentUnit[HTTP_DOWNLOAD_UNIT_SIZE] = ' \0 ' ;
359
- size_t remaining_size = size;
360
-
361
- while (content != NULL && remaining_size > 0 ) {
362
- size_t contentUnitLen = HTTP_DOWNLOAD_UNIT_SIZE;
363
-
364
- if (remaining_size < HTTP_DOWNLOAD_UNIT_SIZE) contentUnitLen = remaining_size;
365
- // due to the memcpy signature, lots of casts are needed
366
- memcpy_P ((void *)contentUnit, (PGM_VOID_P)content, contentUnitLen);
367
-
368
- content += contentUnitLen;
369
- remaining_size -= contentUnitLen;
370
-
371
- // write is so overloaded, had to use the cast to get it pick the right one
372
- _currentClient.write ((const char *)contentUnit, contentUnitLen);
373
- }
321
+ _currentClient.write_P (content, size);
374
322
}
375
323
376
324
0 commit comments