1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-26 07:02:15 +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

@ -179,6 +179,20 @@ class ClientContext {
return reinterpret_cast<char*>(_rx_buf->payload)[_rx_buf_offset];
}
size_t peekBytes(char *dst, size_t size) {
if(!_rx_buf) return 0;
size_t max_size = _rx_buf->tot_len - _rx_buf_offset;
size = (size < max_size) ? size : max_size;
DEBUGV(":pd %d, %d, %d\r\n", size, _rx_buf->tot_len, _rx_buf_offset);
size_t buf_size = _rx_buf->len - _rx_buf_offset;
size_t copy_size = (size < buf_size) ? size : buf_size;
DEBUGV(":rpi %d, %d\r\n", buf_size, copy_size);
os_memcpy(dst, reinterpret_cast<char*>(_rx_buf->payload) + _rx_buf_offset, copy_size);
return copy_size;
}
void flush() {
if(!_rx_buf) {
return;