Skip to content

Commit 88293a4

Browse files
committed
Implement WiFiClient.peek()
Thanks @miomir1981
1 parent 06a76ee commit 88293a4

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Diff for: libraries/WiFi/src/WiFiClient.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,20 @@ int WiFiClient::read(uint8_t *buf, size_t size)
237237
return res;
238238
}
239239

240+
int WiFiClient::peek()
241+
{
242+
if(!available()) {
243+
return -1;
244+
}
245+
uint8_t data = 0;
246+
int res = recv(fd(), &data, 1, MSG_PEEK);
247+
if(res < 0 && errno != EWOULDBLOCK) {
248+
log_e("%d", errno);
249+
stop();
250+
}
251+
return data;
252+
}
253+
240254
int WiFiClient::available()
241255
{
242256
if(!_connected) {

Diff for: libraries/WiFi/src/WiFiClient.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ class WiFiClient : public Client
4747
int available();
4848
int read();
4949
int read(uint8_t *buf, size_t size);
50-
int peek()
51-
{
52-
return -1;
53-
}
50+
int peek();
5451
void flush();
5552
void stop();
5653
uint8_t connected();

0 commit comments

Comments
 (0)