@@ -30,7 +30,6 @@ extern "C" void esp_yield();
3030extern " C" void esp_schedule ();
3131
3232#include < assert.h>
33- #include < StreamDev.h>
3433#include < esp_priv.h>
3534
3635bool getDefaultPrivateGlobalSyncValue ();
@@ -376,13 +375,12 @@ class ClientContext
376375 return _pcb->state ;
377376 }
378377
379- size_t write (Stream& stream )
378+ size_t write (const char * ds, const size_t dl )
380379 {
381380 if (!_pcb) {
382381 return 0 ;
383382 }
384- assert (stream.hasPeekBufferAPI ());
385- return _write_from_source (&stream);
383+ return _write_from_source (ds, dl);
386384 }
387385
388386 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
466464 }
467465 }
468466
469- size_t _write_from_source (Stream * ds)
467+ size_t _write_from_source (const char * ds, const size_t dl )
470468 {
471469 assert (_datasource == nullptr );
472470 assert (!_send_waiting);
473471 _datasource = ds;
472+ _datalen = dl;
474473 _written = 0 ;
475474 _op_start_time = millis ();
476475 do {
477476 if (_write_some ()) {
478477 _op_start_time = millis ();
479478 }
480479
481- if (!_datasource-> available () || _is_timeout () || state () == CLOSED) {
480+ if (_written == _datalen || _is_timeout () || state () == CLOSED) {
482481 if (_is_timeout ()) {
483482 DEBUGV (" :wtmo\r\n " );
484483 }
485484 _datasource = nullptr ;
485+ _datalen = 0 ;
486486 break ;
487487 }
488488
@@ -507,20 +507,21 @@ class ClientContext
507507 return false ;
508508 }
509509
510- DEBUGV (" :wr %d %d\r\n " , _datasource-> peekAvailable () , _written);
510+ DEBUGV (" :wr %d %d\r\n " , _datalen - _written , _written);
511511
512512 bool has_written = false ;
513513
514- while (_datasource ) {
514+ while (_written < _datalen ) {
515515 if (state () == CLOSED)
516516 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);
518519 if (!next_chunk_size)
519520 break ;
520- const char * buf = _datasource-> peekBuffer () ;
521+ const char * buf = _datasource + _written ;
521522
522523 uint8_t flags = 0 ;
523- if (next_chunk_size < _datasource-> peekAvailable () )
524+ if (next_chunk_size < remaining )
524525 // PUSH is meant for peer, telling to give data to user app as soon as received
525526 // PUSH "may be set" when sender has finished sending a "meaningful" data block
526527 // PUSH does not break Nagle
@@ -534,10 +535,9 @@ class ClientContext
534535
535536 err_t err = tcp_write (_pcb, buf, next_chunk_size, flags);
536537
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);
538539
539540 if (err == ERR_OK) {
540- _datasource->peekConsume (next_chunk_size);
541541 _written += next_chunk_size;
542542 has_written = true ;
543543 } else {
@@ -695,7 +695,8 @@ class ClientContext
695695 discard_cb_t _discard_cb;
696696 void * _discard_cb_arg;
697697
698- Stream* _datasource = nullptr ;
698+ const char * _datasource = nullptr ;
699+ size_t _datalen = 0 ;
699700 size_t _written = 0 ;
700701 uint32_t _timeout_ms = 5000 ;
701702 uint32_t _op_start_time = 0 ;
0 commit comments