10000 wip cc · esp8266/Arduino@c14eeef · GitHub
[go: up one dir, main page]

Skip to content

Commit c14eeef

Browse files
committed
wip cc
1 parent b4a918f commit c14eeef

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

libraries/ESP8266WiFi/src/include/ClientContext.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,17 @@ class ClientContext
437437
if (!next_chunk_size)
438438
break;
439439
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);
443451
DEBUGV(":wrc %d %d %d\r\n", next_chunk_size, will_send, (int)err);
444452
if (err == ERR_OK) {
445453
_datasource->release_buffer(buf, next_chunk_size);
@@ -452,7 +460,7 @@ class ClientContext
452460
}
453461
}
454462

455-
if (tcp_nagle_disabled(_pcb) && has_written)
463+
if (has_written && tcp_nagle_disabled(_pcb))
456464
// handle nagle manually because of TCP_WRITE_FLAG_MORE
457465
// lwIP's tcp_output: "Find out what we can send and send it"
458466
tcp_output(_pcb);
@@ -482,14 +490,13 @@ class ClientContext
482490

483491
void _consume(size_t size)
484492
{
493+
if(_pcb)
494+
tcp_recved(_pcb, size);
485495
ptrdiff_t left = _rx_buf->len - _rx_buf_offset - size;
486496
if(left > 0) {
487497
_rx_buf_offset += size;
488498
} else if(!_rx_buf->next) {
489499
DEBUGV(":c0 %d, %d\r\n", size, _rx_buf->tot_len);
490-
if(_pcb) {
491-
tcp_recved(_pcb, _rx_buf->len);
492-
}
493500
pbuf_free(_rx_buf);
494501
_rx_buf = 0;
495502
_rx_buf_offset = 0;
@@ -499,9 +506,6 @@ class ClientContext
499506
_rx_buf = _rx_buf->next;
500507
_rx_buf_offset = 0;
501508
pbuf_ref(_rx_buf);
502-
if(_pcb) {
503-
tcp_recved(_pcb, head->len);
504-
}
505509
pbuf_free(head);
506510
}
507511
}

0 commit comments

Comments
 (0)
0