8000 fixes for WiFiClient::write(Stream) by d-a-v · Pull Request #7987 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

fixes for WiFiClient::write(Stream) #7987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove stream dependance in CLientContext
  • Loading branch information
d-a-v committed Apr 21, 2021
commit e1083c701354123c12cb7b76ba16655faea00cb0
5 changes: 2 additions & 3 deletions libraries/ESP8266WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size)
return 0;
}
_client->setTimeout(_timeout);
StreamConstPtr ptr(buf, size);
return _client->write(ptr);
return _client->write((const char*)buf, size);
}

size_t WiFiClient::write(Stream& stream)
Expand All @@ -225,7 +224,7 @@ size_t WiFiClient::write(Stream& stream)
{
return 0;
}
// core up to 2.7.4 was equivalent to this from within ClientContext
// core up to 2.7.4 was equivalent to this
return stream.sendAll(this);
}

Expand Down
28 changes: 15 additions & 13 deletions libraries/ESP8266WiFi/src/include/ClientContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,12 @@ class ClientContext
return _pcb->state;
}

size_t write(Stream& stream)
size_t write(const char* ds, const size_t dl)
{
if (!_pcb) {
return 0;
}
assert(stream.hasPeekBufferAPI());
return _write_from_source(&stream);
return _write_from_source(ds, dl);
}

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)
Expand Down Expand Up @@ -466,23 +465,25 @@ class ClientContext
}
}

size_t _write_from_source(Stream* ds)
size_t _write_from_source(const char* ds, const size_t dl)
{
assert(_datasource == nullptr);
assert(!_send_waiting);
_datasource = ds;
_datalen = dl;
_written = 0;
_op_start_time = millis();
do {
if (_write_some()) {
_op_start_time = millis();
}

if (!_datasource->available() || _is_timeout() || state() == CLOSED) {
if (_written == _datalen || _is_timeout() || state() == CLOSED) {
if (_is_timeout()) {
DEBUGV(":wtmo\r\n");
}
_datasource = nullptr;
_datalen = 0;
break;
}

Expand All @@ -507,20 +508,21 @@ class ClientContext
return false;
}

DEBUGV(":wr %d %d\r\n", _datasource->peekAvailable(), _written);
DEBUGV(":wr %d %d\r\n", _datalen - _written, _written);

bool has_written = false;

while (_datasource) {
while (_written < _datalen) {
if (state() == CLOSED)
return false;
size_t next_chunk_size = std::min((size_t)tcp_sndbuf(_pcb), _datasource->peekAvailable());
const auto remaining = _datalen - _written;
size_t next_chunk_size = std::min((size_t)tcp_sndbuf(_pcb), remaining);
if (!next_chunk_size)
break;
const char* buf = _datasource->peekBuffer();
const char* buf = _datasource + _written;

uint8_t flags = 0;
if (next_chunk_size < _datasource->peekAvailable())
if (next_chunk_size < remaining)
// PUSH is meant for peer, telling to give data to user app as soon as received
// PUSH "may be set" when sender has finished sending a "meaningful" data block
// PUSH does not break Nagle
Expand All @@ -534,10 +536,9 @@ class ClientContext

err_t err = tcp_write(_pcb, buf, next_chunk_size, flags);

DEBUGV(":wrc %d %d %d\r\n", next_chunk_size, _datasource->peekAvailable(), (int)err);
DEBUGV(":wrc %d %d %d\r\n", next_chunk_size, remaining, (int)err);

if (err == ERR_OK) {
_datasource->peekConsume(next_chunk_size);
_written += next_chunk_size;
has_written = true;
} else {
Expand Down Expand Up @@ -695,7 +696,8 @@ class ClientContext
discard_cb_t _discard_cb;
void* _discard_cb_arg;

Stream* _datasource = nullptr;
const char* _datasource = nullptr;
size_t _datalen = 0;
size_t _written = 0;
uint32_t _timeout_ms = 5000;
uint32_t _op_start_time = 0;
Expand Down
0