@@ -483,20 +483,24 @@ class ClientContext
483
483
if (!next_chunk_size)
484
484
break ;
485
485
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)
494
495
if (!_sync)
495
496
// user data must be copied when data are sent but not yet acknowledged
496
497
// (with sync, we wait for acknowledgment before returning to user)
497
498
flags |= TCP_WRITE_FLAG_COPY;
499
+
498
500
err_t err = tcp_write (_pcb, buf, next_chunk_size, flags);
501
+
499
502
DEBUGV (" :wrc %d %d %d\r\n " , next_chunk_size, _datasource->available (), (int )err);
503
+
500
504
if (err == ERR_OK) {
501
505
_datasource->release_buffer (buf, next_chunk_size);
502
506
_written += next_chunk_size;
@@ -508,10 +512,11 @@ class ClientContext
508
512
}
509
513
}
510
514
511
- if (has_written && (_sync || tcp_nagle_disabled (_pcb)) )
515
+ if (has_written)
512
516
{
513
- // handle no-Nagle manually because of TCP_WRITE_FLAG_MORE
514
517
// lwIP's tcp_output doc: "Find out what we can send and send it"
518
+ // *with respect to Nagle*
519
+ // more info: https://lists.gnu.org/archive/html/lwip-users/2017-11/msg00134.html
515
520
tcp_output (_pcb);
516
521
}
517
522
0 commit comments