Skip to content

Commit

Permalink
ClientContext: restore TCP PuSH flasg when needed (#5176)
Browse files Browse the repository at this point in the history
fix #5173
  • Loading branch information
d-a-v authored Sep 27, 2018
1 parent 775eb9b commit 5a5af55
Showing 1 changed file with 13 additions and 9 deletions.
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

0 comments on commit 5a5af55

Please sign in to comment.