@@ -437,9 +437,17 @@ class ClientContext
437
437
if (!next_chunk_size)
438
438
break ;
439
439
const uint8_t * buf = _datasource->get_buffer (next_chunk_size);
440
- // TCP_WRITE_FLAG_MORE to remove PUSH flag from packet
441
- // TCP_WRITE_FLAG_MORE implicitely disables nagle (see lwIP's tcp_out.c)
442
- err_t err = tcp_write (_pcb, buf, next_chunk_size, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
440
+ // TCP_WRITE_FLAG_MORE to remove PUSH flag from packet (lwIP's doc), implicitely disables nagle (see lwIP's tcp_out.c)
441
+ // Notes:
442
+ // PUSH is for peer, telling to give to user app as soon as received
443
+ // PUSH may be set when sender has finished sending a meaningful data block
444
+ // Nagle is for delaying local stack, to send less and bigger packets
445
+ uint8_t flags = TCP_WRITE_FLAG_COPY;
446
+ if (!tcp_nagle_disabled (_pcb))
447
+ // nagle enabled, delayed, buffering, bigger packets
448
+ // (When should we use PUSH?)
449
+ flags |= TCP_WRITE_FLAG_MORE;
450
+ err_t err = tcp_write (_pcb, buf, next_chunk_size, flags);
443
451
DEBUGV (" :wrc %d %d %d\r\n " , next_chunk_size, will_send, (int )err);
444
452
if (err == ERR_OK) {
445
453
_datasource->release_buffer (buf, next_chunk_size);
@@ -452,7 +460,7 @@ class ClientContext
452
460
}
453
461
}
454
462
455
- if (tcp_nagle_disabled (_pcb) && has_written )
463
+ if (has_written && tcp_nagle_disabled (_pcb) )
456
464
// handle nagle manually because of TCP_WRITE_FLAG_MORE
457
465
// lwIP's tcp_output: "Find out what we can send and send it"
458
466
tcp_output (_pcb);
@@ -482,14 +490,13 @@ class ClientContext
482
490
483
491
void _consume (size_t size)
484
492
{
493
+ if (_pcb)
494
+ tcp_recved (_pcb, size);
485
495
ptrdiff_t left = _rx_buf->len - _rx_buf_offset - size;
486
496
if (left > 0 ) {
487
497
_rx_buf_offset += size;
488
498
} else if (!_rx_buf->next ) {
489
499
DEBUGV (" :c0 %d, %d\r\n " , size, _rx_buf->tot_len );
490
- if (_pcb) {
491
- tcp_recved (_pcb, _rx_buf->len );
492
- }
493
500
pbuf_free (_rx_buf);
494
501
_rx_buf = 0 ;
495
502
_rx_buf_offset = 0 ;
@@ -499,9 +506,6 @@ class ClientContext
499
506
_rx_buf = _rx_buf->next ;
500
507
_rx_buf_offset = 0 ;
501
508
pbuf_ref (_rx_buf);
502
- if (_pcb) {
503
- tcp_recved (_pcb, head->len );
504
- }
505
509
pbuf_free (head);
506
510
}
507
511
}
0 commit comments