Skip to content

Commit ee61207

Browse files
committed
WiFiServer: check previous received client socket for data before querying a new one
1 parent d960437 commit ee61207

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/WiFiServer.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ extern "C" {
3030
#include "WiFiServer.h"
3131

3232
WiFiServer::WiFiServer(uint16_t port) :
33-
_sock(NO_SOCKET_AVAIL)
33+
_sock(NO_SOCKET_AVAIL),
34+
_lastSock(NO_SOCKET_AVAIL)
3435
{
3536
_port = port;
3637
}
@@ -49,7 +50,19 @@ WiFiClient WiFiServer::available(byte* status)
4950
int sock = NO_SOCKET_AVAIL;
5051

5152
if (_sock != NO_SOCKET_AVAIL) {
52-
sock = ServerDrv::availServer(_sock);
53+
// check previous received client socket
54+
if (_lastSock != NO_SOCKET_AVAIL) {
55+
WiFiClient client(_lastSock);
56+
57+
if (client.connected() && client.available()) {
58+
sock = _lastSock;
59+
}
60+
}
61+
62+
if (sock == NO_SOCKET_AVAIL) {
63+
// check for new client socket
64+
sock = ServerDrv::availServer(_sock);
65+
}
5366
}
5467

5568
if (sock != NO_SOCKET_AVAIL) {
@@ -59,6 +72,8 @@ WiFiClient WiFiServer::available(byte* status)
5972
*status = client.status();
6073
}
6174

75+
_lastSock = sock;
76+
6277
return client;
6378
}
6479

src/WiFiServer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class WiFiClient;
3232
class WiFiServer : public Server {
3333
private:
3434
uint8_t _sock;
35+
uint8_t _lastSock;
3536
uint16_t _port;
3637
void* pcb;
3738
public:

0 commit comments

Comments
 (0)