Skip to content
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

WiFiServer modernization #1871

Merged
merged 2 commits into from
Dec 2, 2023
Merged
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
2 changes: 1 addition & 1 deletion libraries/WebServer/src/WebServerTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void WebServerTemplate<ServerType, DefaultPort>::handleClient() {
_currentClient = nullptr;
}

_currentClient = new ClientType(_server.available());
_currentClient = new ClientType(_server.accept());
if (!_currentClient) {
if (_nullDelay) {
delay(1);
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/examples/WiFiServer/WiFiServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void loop() {
delay(1000);
Serial.printf("--loop %d\n", ++i);
delay(10);
WiFiClient client = server.available();
WiFiClient client = server.accept();
if (!client) {
return;
}
Expand Down
8 changes: 8 additions & 0 deletions libraries/WiFi/src/WiFiServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,18 @@ void WiFiServer::close() {
_listen_pcb = nullptr;
}

void WiFiServer::end() {
close();
}

void WiFiServer::stop() {
close();
}

WiFiServer::operator bool() {
return (status() != CLOSED);
}

template<typename T>
T* slist_append_tail(T* head, T* item) {
if (!head) {
Expand Down
6 changes: 4 additions & 2 deletions libraries/WiFi/src/WiFiServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ class WiFiServer {

public:
WiFiServer(const IPAddress& addr, uint16_t port);
WiFiServer(uint16_t port);
WiFiServer(uint16_t port = 23);
virtual ~WiFiServer() {}
WiFiClient accept(); // https://www.arduino.cc/en/Reference/EthernetServerAccept
WiFiClient available(uint8_t* status = nullptr);
WiFiClient available(uint8_t* status = nullptr) __attribute__((deprecated("Use accept().")));

bool hasClient();
// hasClientData():
Expand All @@ -95,8 +95,10 @@ class WiFiServer {
bool getNoDelay();
uint8_t status();
uint16_t port() const;
void end();
void close();
void stop();
explicit operator bool();

using ClientType = WiFiClient;

Expand Down
4 changes: 2 additions & 2 deletions libraries/WiFi/src/WiFiServerSecureBearSSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class WiFiClientSecure;
class WiFiServerSecure : public WiFiServer {
public:
WiFiServerSecure(IPAddress addr, uint16_t port);
WiFiServerSecure(uint16_t port);
WiFiServerSecure(uint16_t port = 22);
WiFiServerSecure(const WiFiServerSecure &rhs);
virtual ~WiFiServerSecure();

Expand Down Expand Up @@ -65,7 +65,7 @@ class WiFiServerSecure : public WiFiServer {

// If awaiting connection available and authenticated (i.e. client cert), return it.
WiFiClientSecure accept(); // https://www.arduino.cc/en/Reference/EthernetServerAccept
WiFiClientSecure available(uint8_t* status = nullptr);
WiFiClientSecure available(uint8_t* status = nullptr) __attribute__((deprecated("Use accept().")));

WiFiServerSecure& operator=(const WiFiServerSecure&) = default;

Expand Down