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

Stream::send() (#6979)

This commit is contained in:
david gauchard
2021-03-15 01:36:20 +01:00
committed by GitHub
parent 4cc1472821
commit c720c0d9e8
48 changed files with 2136 additions and 650 deletions

View File

@ -37,22 +37,8 @@ namespace esp8266webserver {
template <typename ServerType>
static bool readBytesWithTimeout(typename ServerType::ClientType& client, size_t maxLength, String& data, int timeout_ms)
{
if (!data.reserve(maxLength + 1))
return false;
data[0] = 0; // data.clear()??
while (data.length() < maxLength) {
int tries = timeout_ms;
size_t avail;
while (!(avail = client.available()) && tries--)
delay(1);
if (!avail)
break;
if (data.length() + avail > maxLength)
avail = maxLength - data.length();
while (avail--)
data += (char)client.read();
}
return data.length() == maxLength;
S2Stream dataStream(data);
return client.sendSize(dataStream, maxLength, timeout_ms) == maxLength;
}
template <typename ServerType>