@@ -30,7 +30,6 @@ extern "C" void esp_yield();
30
30
extern " C" void esp_schedule ();
31
31
32
32
#include < assert.h>
33
- #include < StreamDev.h>
34
33
#include < esp_priv.h>
35
34
36
35
bool getDefaultPrivateGlobalSyncValue ();
@@ -376,13 +375,12 @@ class ClientContext
376
375
return _pcb->state ;
377
376
}
378
377
379
- size_t write (Stream& stream )
378
+ size_t write (const char * ds, const size_t dl )
380
379
{
381
380
if (!_pcb) {
382
381
return 0 ;
383
382
}
384
- assert (stream.hasPeekBufferAPI ());
385
- return _write_from_source (&stream);
383
+ return _write_from_source (ds, dl);
386
384
}
387
385
388
386
void keepAlive (uint16_t idle_sec = TCP_DEFAULT_KEEPALIVE_IDLE_SEC, uint16_t intv_sec = TCP_DEFAULT_KEEPALIVE_INTERVAL_SEC, uint8_t count = TCP_DEFAULT_KEEPALIVE_COUNT)
@@ -466,23 +464,25 @@ class ClientContext
466
464
}
467
465
}
468
466
469
- size_t _write_from_source (Stream * ds)
467
+ size_t _write_from_source (const char * ds, const size_t dl )
470
468
{
471
469
assert (_datasource == nullptr );
472
470
assert (!_send_waiting);
473
471
_datasource = ds;
472
+ _datalen = dl;
474
473
_written = 0 ;
475
474
_op_start_time = millis ();
476
475
do {
477
476
if (_write_some ()) {
478
477
_op_start_time = millis ();
479
478
}
480
479
481
- if (!_datasource-> available () || _is_timeout () || state () == CLOSED) {
480
+ if (_written == _datalen || _is_timeout () || state () == CLOSED) {
482
481
if (_is_timeout ()) {
483
482
DEBUGV (" :wtmo\r\n " );
484
483
}
485
484
_datasource = nullptr ;
485
+ _datalen = 0 ;
486
486
break ;
487
487
}
488
488
@@ -507,20 +507,21 @@ class ClientContext
507
507
return false ;
508
508
}
509
509
510
- DEBUGV (" :wr %d %d\r\n " , _datasource-> peekAvailable () , _written);
510
+ DEBUGV (" :wr %d %d\r\n " , _datalen - _written , _written);
511
511
512
512
bool has_written = false ;
513
513
514
- while (_datasource ) {
514
+ while (_written < _datalen ) {
515
515
if (state () == CLOSED)
516
516
return false ;
517
- size_t next_chunk_size = std::min ((size_t )tcp_sndbuf (_pcb), _datasource->peekAvailable ());
517
+ const auto remaining = _datalen - _written;
518
+ size_t next_chunk_size = std::min ((size_t )tcp_sndbuf (_pcb), remaining);
518
519
if (!next_chunk_size)
519
520
break ;
520
- const char * buf = _datasource-> peekBuffer () ;
521
+ const char * buf = _datasource + _written ;
521
522
522
523
uint8_t flags = 0 ;
523
- if (next_chunk_size < _datasource-> peekAvailable () )
524
+ if (next_chunk_size < remaining )
524
525
// PUSH is meant for peer, telling to give data to user app as soon as received
525
526
// PUSH "may be set" when sender has finished sending a "meaningful" data block
526
527
// PUSH does not break Nagle
@@ -534,10 +535,9 @@ class ClientContext
534
535
535
536
err_t err = tcp_write (_pcb, buf, next_chunk_size, flags);
536
537
537
- DEBUGV (" :wrc %d %d %d\r\n " , next_chunk_size, _datasource-> peekAvailable () , (int )err);
538
+ DEBUGV (" :wrc %d %d %d\r\n " , next_chunk_size, remaining , (int )err);
538
539
539
540
if (err == ERR_OK) {
540
- _datasource->peekConsume (next_chunk_size);
541
541
_written += next_chunk_size;
542
542
has_written = true ;
543
543
} else {
@@ -695,7 +695,8 @@ class ClientContext
695
695
discard_cb_t _discard_cb;
696
696
void * _discard_cb_arg;
697
697
698
- Stream* _datasource = nullptr ;
698
+ const char * _datasource = nullptr ;
699
+ size_t _datalen = 0 ;
699
700
size_t _written = 0 ;
700
701
uint32_t _timeout_ms = 5000 ;
701
702
uint32_t _op_start_time = 0 ;
0 commit comments