Skip to content

ClientConnection uses too much heap when streaming files #2871

Closed
@joelucid

Description

@joelucid

It should be possible to stream arbitrary large files to a ClientContext. However this is done via a BufferedStreamDataSource which allocates a buffer in RAM to keep the whole memory chunk requested in get_buffer. These requests can ask for > 2800 bytes at a time.

To preserve memory the size of the chunk requested should be limited. The following patch achieves that:

diff --git a/libraries/ESP8266WiFi/src/include/ClientContext.h b/libraries/ESP8266WiFi/src/include/ClientContext.h
index d2ee090..df12760 100644
--- a/libraries/ESP8266WiFi/src/include/ClientContext.h
+++ b/libraries/ESP8266WiFi/src/include/ClientContext.h
@@ -346,6 +346,7 @@ protected:
can_send = 0;
}
size_t will_send = (can_send < left) ? can_send : left;

  •   if( will_send > 256 ) will_send = 256;
       if (will_send) {
           const uint8_t* buf = _datasource->get_buffer(will_send);
           err_t err = tcp_write(_pcb, buf, will_send, TCP_WRITE_FLAG_COPY);
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions