Skip to content

WiFiSever - Arduino API available() and accept() #7605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion libraries/ESP8266WiFi/src/WiFiServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ bool WiFiServer::hasClient() {
return false;
}

WiFiClient WiFiServer::available(byte* status) {
WiFiClient WiFiServer::accept(byte* status) {
(void) status;
if (_unclaimed) {
WiFiClient result(_unclaimed);
Expand All @@ -135,6 +135,24 @@ WiFiClient WiFiServer::available(byte* status) {
return WiFiClient();
}

WiFiClient WiFiServer::available() {
for (uint8_t i = 0; i < MAX_MONITORED_CLIENTS; i++) {
WiFiClient& client = connectedClients[i];
if (client && client.status() == CLOSED) {
client = WiFiClient();
}
if (!client) {
client = accept();
}
}
for (uint8_t i = 0; i < MAX_MONITORED_CLIENTS; i++) {
WiFiClient& client = connectedClients[i];
if (client.available())
return client;
}
return WiFiClient();
}

uint8_t WiFiServer::status() {
if (!_listen_pcb)
return CLOSED;
Expand Down
10 changes: 9 additions & 1 deletion libraries/ESP8266WiFi/src/WiFiServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ extern "C" {
class ClientContext;
class WiFiClient;

#ifndef MAX_MONITORED_CLIENTS
#define MAX_MONITORED_CLIENTS 5
#endif

class WiFiServer : public Server {
// Secure server needs access to all the private entries here
protected:
Expand All @@ -74,13 +78,17 @@ class WiFiServer : public Server {

ClientContext* _unclaimed;
ClientContext* _discarded;

WiFiClient connectedClients[MAX_MONITORED_CLIENTS];

enum { _ndDefault, _ndFalse, _ndTrue } _noDelay = _ndDefault;

public:
WiFiServer(const IPAddress& addr, uint16_t port);
WiFiServer(uint16_t port);
virtual ~WiFiServer() {}
WiFiClient available(uint8_t* status = NULL);
WiFiClient accept(uint8_t* status = NULL);
WiFiClient available();
bool hasClient();
void begin();
void begin(uint16_t port);
Expand Down