Skip to content

Commit 2e9bda8

Browse files
committed
ClientContext: restore TCP PuSH flasg when needed
fix esp8266#5173
1 parent 775eb9b commit 2e9bda8

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

libraries/ESP8266WiFi/src/include/ClientContext.h

+13-9
Original file line numberDiff line numberDiff line change
@@ -483,20 +483,24 @@ class ClientContext
483483
if (!next_chunk_size)
484484
break;
485485
const uint8_t* buf = _datasource->get_buffer(next_chunk_size);
486-
// use TCP_WRITE_FLAG_MORE to remove PUSH flag from packet (lwIP's doc),
487-
// because PUSH code implicitely disables Nagle code (see lwIP's tcp_out.c)
488-
// Notes:
489-
// PUSH is meant for peer, telling to give data to user app as soon as received
490-
// PUSH "may be set" when sender has finished sending a meaningful data block
491-
// PUSH is quite unclear in its application
492-
// Nagle is for shortly delaying outgoing data, to send less/bigger packets
493-
uint8_t flags = TCP_WRITE_FLAG_MORE; // do not tcp-PuSH
486+
487+
uint8_t flags = 0;
488+
if (next_chunk_size < _datasource->available())
489+
// PUSH is meant for peer, telling to give data to user app as soon as received
490+
// PUSH "may be set" when sender has finished sending a "meaningful" data block
491+
// PUSH does not break Nagle
492+
// #5173: windows needs this flag
493+
// more info: https://lists.gnu.org/archive/html/lwip-users/2009-11/msg00018.html
494+
flags |= TCP_WRITE_FLAG_MORE; // do not tcp-PuSH (yet)
494495
if (!_sync)
495496
// user data must be copied when data are sent but not yet acknowledged
496497
// (with sync, we wait for acknowledgment before returning to user)
497498
flags |= TCP_WRITE_FLAG_COPY;
499+
498500
err_t err = tcp_write(_pcb, buf, next_chunk_size, flags);
501+
499502
DEBUGV(":wrc %d %d %d\r\n", next_chunk_size, _datasource->available(), (int)err);
503+
500504
if (err == ERR_OK) {
501505
_datasource->release_buffer(buf, next_chunk_size);
502506
_written += next_chunk_size;
@@ -512,7 +516,7 @@ class ClientContext
512516
{
513517
// lwIP's tcp_output doc: "Find out what we can send and send it"
514518
// *with respect to Nagle*
515-
// more insights: https://lists.gnu.org/archive/html/lwip-users/2017-11/msg00134.html
519+
// more info: https://lists.gnu.org/archive/html/lwip-users/2017-11/msg00134.html
516520
tcp_output(_pcb);
517521
}
518522

0 commit comments

Comments
 (0)