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 1 commit
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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to a ClientContext member variable? Then we can later add an API to WiFiClient to configure the chunk size at runtime. This variable can be default-initalized to 256 for now.


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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines seem to use TABs for indentation, but the original file uses spaces. Could you please reformat to match indentation of the surrounding code?

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