1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-06 05:21:22 +03:00

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

* ClientConnection uses too much heap when streaming files #2871

* make write_chunk_size a member variable

* untabify
This commit is contained in:
joelucid 2017-01-31 09:04:45 +01:00 committed by Ivan Grokhotkov
parent 90729ea50c
commit 61787b23af

View File

@ -333,7 +333,6 @@ protected:
return _written;
}
void _write_some()
{
if (!_datasource || !_pcb) {
@ -346,15 +345,20 @@ protected:
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;
@ -479,6 +483,7 @@ private:
DataSource* _datasource = nullptr;
size_t _written = 0;
size_t _write_chunk_size = 256;
bool _noblock = false;
bool _send_waiting = false;
};