@@ -296,31 +296,29 @@ class ClientContext
296
296
_rx_buf_offset = 0 ;
297
297
}
298
298
299
- bool wait_until_sent (int max_wait_ms = WIFICLIENT_MAX_FLUSH_WAIT_MS )
299
+ void wait_until_sent ()
300
300
{
301
- if (!_pcb)
302
- return true ;
303
-
304
- tcp_output (_pcb);
305
-
306
301
// https://github.com/esp8266/Arduino/pull/3967#pullrequestreview-83451496
307
302
// option 1 done
308
303
// option 2 / _write_some() not necessary since _datasource is always nullptr here
309
304
310
- max_wait_ms++;
305
+ if (!_pcb)
306
+ return ;
307
+
308
+ tcp_output (_pcb);
309
+
310
+ int max_wait_ms = WIFICLIENT_MAX_FLUSH_WAIT_MS + 1 ;
311
311
312
312
// wait for peer's acks flushing lwIP's output buffer
313
313
while (state () == ESTABLISHED && tcp_sndbuf (_pcb) != TCP_SND_BUF && --max_wait_ms)
314
- delay (1 ); // esp_ schedule+yield
314
+ delay (1 ); // yields
315
315
316
316
#ifdef DEBUGV
317
317
if (max_wait_ms == 0 ) {
318
318
// wait until sent: timeout
319
319
DEBUGV (" :wustmo\n " );
320
320
}
321
321
#endif
322
-
323
- return max_wait_ms > 0 ;
324
322
}
325
323
326
324
uint8_t state () const
@@ -461,13 +459,15 @@ class ClientContext
461
459
if (!next_chunk_size)
462
460
break ;
463
461
const uint8_t * buf = _datasource->get_buffer (next_chunk_size);
464
- // TCP_WRITE_FLAG_MORE to remove PUSH flag from packet (lwIP's doc), implicitely disables nagle (see lwIP's tcp_out.c)
462
+ // use TCP_WRITE_FLAG_MORE to remove PUSH flag from packet (lwIP's doc),
463
+ // because PUSH implicitely disables nagle (see lwIP's tcp_out.c)
465
464
// Notes:
466
- // PUSH is for peer, telling to give to user app as soon as received
467
- // PUSH may be set when sender has finished sending a meaningful data block
468
- // Nagle is for delaying local stack , to send less and bigger packets
469
- uint8_t flags = TCP_WRITE_FLAG_MORE; // do not tcp-PuSH (XXX always?)
465
+ // PUSH is for peer, telling to give data to user app as soon as received
466
+ // PUSH " may be set" when sender has finished sending a meaningful data block
467
+ // Nagle is for delaying local data , to send less/ bigger packets
468
+ uint8_t flags = TCP_WRITE_FLAG_MORE; // do not tcp-PuSH
470
469
if (!_sync)
470
+ // user data will not stay in place when data are sent but not acknowledged
471
471
flags |= TCP_WRITE_FLAG_COPY;
472
472
err_t err = tcp_write (_pcb, buf, next_chunk_size, flags);
473
473
DEBUGV (" :wrc %d %d %d\r\n " , next_chunk_size, will_send, (int )err);
@@ -484,8 +484,8 @@ class ClientContext
484
484
485
485
if (has_written && (_sync || tcp_nagle_disabled (_pcb)))
486
486
{
487
- // handle nagle manually because of TCP_WRITE_FLAG_MORE
488
- // lwIP's tcp_output: "Find out what we can send and send it"
487
+ // handle no-Nagle manually because of TCP_WRITE_FLAG_MORE
488
+ // lwIP's tcp_output doc : "Find out what we can send and send it"
489
489
tcp_output (_pcb);
490
490
}
491
491
@@ -494,13 +494,10 @@ class ClientContext
494
494
495
495
void _write_some_from_cb ()
496
496
{
497
- // lwIP needs feeding
498
- _write_some ();
499
-
500
497
if (_send_waiting == 1 ) {
501
498
_send_waiting--;
499
+ esp_schedule ();
502
500
}
503
- esp_schedule ();
504
501
}
505
502
506
503
err_t _acked (tcp_pcb* pcb, uint16_t len)
0 commit comments