Skip to content

Commit

Permalink
ClientConnection uses too much heap when streaming files esp8266#2871
Browse files Browse the repository at this point in the history
  • Loading branch information
joelucid committed Jan 17, 2017
1 parent a444898 commit 9c0b0bc
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions libraries/ESP8266WiFi/src/include/ClientContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ class ClientContext
return _written;
}

#define TCP_WRITE_CHUNK_SIZE 256

void _write_some()
{
Expand All @@ -345,16 +346,21 @@ class ClientContext
if (_pcb->snd_queuelen >= TCP_SND_QUEUELEN) {
can_send = 0;
}
size_t will_send = (can_send < left) ? can_send : left;
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);
_datasource->release_buffer(buf, will_send);
size_t will_send = (can_send < left) ? can_send : left;
bool did_write = false;
while( will_send ) {
size_t next_chunk =
will_send > TCP_WRITE_CHUNK_SIZE ? TCP_WRITE_CHUNK_SIZE : will_send;
const uint8_t* buf = _datasource->get_buffer(next_chunk);
err_t err = tcp_write(_pcb, buf, next_chunk, TCP_WRITE_FLAG_COPY);
_datasource->release_buffer(buf, next_chunk);
if (err == ERR_OK) {
_written += will_send;
tcp_output(_pcb);
_written += next_chunk;
did_write = true;
}
will_send -= next_chunk;
}
if( did_write ) tcp_output(_pcb);

if (!_datasource->available() || _noblock) {
delete _datasource;
Expand Down

0 comments on commit 9c0b0bc

Please sign in to comment.