Skip to content

ClientConnection uses too much heap when streaming files #2871 #2874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 31, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -474,6 +478,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