Skip to content

ClientContext: restore TCP PuSH flag when needed #5176

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 1 commit into from
Sep 27, 2018
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
22 changes: 13 additions & 9 deletions libraries/ESP8266WiFi/src/include/ClientContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,20 +483,24 @@ class ClientContext
if (!next_chunk_size)
break;
const uint8_t* buf = _datasource->get_buffer(next_chunk_size);
// use TCP_WRITE_FLAG_MORE to remove PUSH flag from packet (lwIP's doc),
// because PUSH code implicitely disables Nagle code (see lwIP's tcp_out.c)
// Notes:
// PUSH is meant for peer, telling to give data to user app as soon as received
// PUSH "may be set" when sender has finished sending a meaningful data block
// PUSH is quite unclear in its application
// Nagle is for shortly delaying outgoing data, to send less/bigger packets
uint8_t flags = TCP_WRITE_FLAG_MORE; // do not tcp-PuSH

uint8_t flags = 0;
if (next_chunk_size < _datasource->available())
// PUSH is meant for peer, telling to give data to user app as soon as received
// PUSH "may be set" when sender has finished sending a "meaningful" data block
// PUSH does not break Nagle
// #5173: windows needs this flag
// more info: https://lists.gnu.org/archive/html/lwip-users/2009-11/msg00018.html
flags |= TCP_WRITE_FLAG_MORE; // do not tcp-PuSH (yet)
if (!_sync)
// user data must be copied when data are sent but not yet acknowledged
// (with sync, we wait for acknowledgment before returning to user)
flags |= TCP_WRITE_FLAG_COPY;

err_t err = tcp_write(_pcb, buf, next_chunk_size, flags);

DEBUGV(":wrc %d %d %d\r\n", next_chunk_size, _datasource->available(), (int)err);

if (err == ERR_OK) {
_datasource->release_buffer(buf, next_chunk_size);
_written += next_chunk_size;
Expand All @@ -512,7 +516,7 @@ class ClientContext
{
// lwIP's tcp_output doc: "Find out what we can send and send it"
// *with respect to Nagle*
// more insights: https://lists.gnu.org/archive/html/lwip-users/2017-11/msg00134.html
// more info: https://lists.gnu.org/archive/html/lwip-users/2017-11/msg00134.html
tcp_output(_pcb);
}

Expand Down