1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-27 18:02:17 +03:00

fixes for WiFiClient::write(Stream) (#7987)

fixes for WiFiClient::write(Stream) and Stream transfers
- remove deprecated WiFiClient::write(Stream,size)
- fix and deprecate WiFiClient::write(Stream) to use Stream::sendAll instead of ::sendAvailable
- update ESP8266WebServer::streamFile to use file.sendAll(client) instead of client.write(file)
- remove stream dependence in ClientContext
- Stream::send(): honor timeout in all case, avoid short transfer when output is temporarily full
- example WiFiEcho: show sendAll and sendAvailable
This commit is contained in:
david gauchard
2021-04-27 16:02:19 +02:00
committed by GitHub
parent 457692101a
commit f4178e58dc
7 changed files with 46 additions and 91 deletions

View File

@ -223,9 +223,9 @@ public:
return _sock >= 0? ESTABLISHED: CLOSED;
}
size_t write(const uint8_t* data, size_t size)
size_t write(const char* data, size_t size)
{
ssize_t ret = mockWrite(_sock, data, size, _timeout_ms);
ssize_t ret = mockWrite(_sock, (const uint8_t*)data, size, _timeout_ms);
if (ret < 0)
{
abort();
@ -234,28 +234,6 @@ public:
return ret;
}
size_t write(Stream& stream)
{
size_t avail = stream.available();
uint8_t buf [avail];
avail = stream.readBytes(buf, avail);
size_t totwrote = 0;
uint8_t* w = buf;
while (avail && _sock >= 0)
{
size_t wrote = write(w, avail);
w += wrote;
avail -= wrote;
totwrote += wrote;
}
return totwrote;
}
size_t write_P(PGM_P buf, size_t size)
{
return write((const uint8_t*)buf, size);
}
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)
{
(void) idle_sec;