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
…esp8266#2874)

* ClientConnection uses too much heap when streaming files esp8266#2871

* make write_chunk_size a member variable

* untabify
  • Loading branch information
joelucid authored and igrr committed Jan 31, 2017
1 parent 90729ea commit 61787b2
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions libraries/ESP8266WiFi/src/include/ClientContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ class ClientContext
return _written;
}


void _write_some()
{
if (!_datasource || !_pcb) {
Expand All @@ -346,15 +345,20 @@ class ClientContext
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);
bool did_write = false;
while( will_send ) {
size_t next_chunk =
will_send > _write_chunk_size ? _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 Expand Up @@ -479,6 +483,7 @@ class ClientContext

DataSource* _datasource = nullptr;
size_t _written = 0;
size_t _write_chunk_size = 256;
bool _noblock = false;
bool _send_waiting = false;
};
Expand Down

0 comments on commit 61787b2

Please sign in to comment.