1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-12 01:53:07 +03:00

add function peekBytes to WiFiClient/WiFiClientSecure to allow to peek multiple bytes if possible

This commit is contained in:
Markus Sattler
2015-12-19 14:37:36 +01:00
parent 898737422e
commit 5333ebfed7
5 changed files with 72 additions and 0 deletions

View File

@ -239,6 +239,27 @@ int WiFiClient::peek()
return _client->peek();
}
size_t WiFiClient::peekBytes(uint8_t *buffer, size_t length) {
size_t count = 0;
if(!_client) {
return 0;
}
_startMillis = millis();
while((available() < (int) length) && ((millis() - _startMillis) < _timeout)) {
yield();
}
if(available() < (int) length) {
count = available();
} else {
count = length;
}
return _client->peekBytes((char *)buffer, count);
}
void WiFiClient::flush()
{
if (_client)