Implement WiFiClient.peek()

Thanks @miomir1981
This commit is contained in:
me-no-dev 2017-05-22 15:27:34 +03:00
parent 06a76eebe8
commit 88293a4284
2 changed files with 15 additions and 4 deletions

View File

@ -237,6 +237,20 @@ int WiFiClient::read(uint8_t *buf, size_t size)
return res;
}
int WiFiClient::peek()
{
if(!available()) {
return -1;
}
uint8_t data = 0;
int res = recv(fd(), &data, 1, MSG_PEEK);
if(res < 0 && errno != EWOULDBLOCK) {
log_e("%d", errno);
stop();
}
return data;
}
int WiFiClient::available()
{
if(!_connected) {

View File

@ -47,10 +47,7 @@ public:
int available();
int read();
int read(uint8_t *buf, size_t size);
int peek()
{
return -1;
}
int peek();
void flush();
void stop();
uint8_t connected();