Unverified Commit a1902b5f authored by Juraj Andrássy's avatar Juraj Andrássy Committed by GitHub

WiFiServer modernization (#1871)

parent c2d60774
...@@ -90,7 +90,7 @@ void WebServerTemplate<ServerType, DefaultPort>::handleClient() { ...@@ -90,7 +90,7 @@ void WebServerTemplate<ServerType, DefaultPort>::handleClient() {
_currentClient = nullptr; _currentClient = nullptr;
} }
_currentClient = new ClientType(_server.available()); _currentClient = new ClientType(_server.accept());
if (!_currentClient) { if (!_currentClient) {
if (_nullDelay) { if (_nullDelay) {
delay(1); delay(1);
......
...@@ -34,7 +34,7 @@ void loop() { ...@@ -34,7 +34,7 @@ void loop() {
delay(1000); delay(1000);
Serial.printf("--loop %d\n", ++i); Serial.printf("--loop %d\n", ++i);
delay(10); delay(10);
WiFiClient client = server.available(); WiFiClient client = server.accept();
if (!client) { if (!client) {
return; return;
} }
......
...@@ -163,10 +163,18 @@ void WiFiServer::close() { ...@@ -163,10 +163,18 @@ void WiFiServer::close() {
_listen_pcb = nullptr; _listen_pcb = nullptr;
} }
void WiFiServer::end() {
close();
}
void WiFiServer::stop() { void WiFiServer::stop() {
close(); close();
} }
WiFiServer::operator bool() {
return (status() != CLOSED);
}
template<typename T> template<typename T>
T* slist_append_tail(T* head, T* item) { T* slist_append_tail(T* head, T* item) {
if (!head) { if (!head) {
......
...@@ -75,10 +75,10 @@ protected: ...@@ -75,10 +75,10 @@ protected:
public: public:
WiFiServer(const IPAddress& addr, uint16_t port); WiFiServer(const IPAddress& addr, uint16_t port);
WiFiServer(uint16_t port); WiFiServer(uint16_t port = 23);
virtual ~WiFiServer() {} virtual ~WiFiServer() {}
WiFiClient accept(); // https://www.arduino.cc/en/Reference/EthernetServerAccept 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(); bool hasClient();
// hasClientData(): // hasClientData():
...@@ -95,8 +95,10 @@ public: ...@@ -95,8 +95,10 @@ public:
bool getNoDelay(); bool getNoDelay();
uint8_t status(); uint8_t status();
uint16_t port() const; uint16_t port() const;
void end();
void close(); void close();
void stop(); void stop();
explicit operator bool();
using ClientType = WiFiClient; using ClientType = WiFiClient;
......
...@@ -31,7 +31,7 @@ class WiFiClientSecure; ...@@ -31,7 +31,7 @@ class WiFiClientSecure;
class WiFiServerSecure : public WiFiServer { class WiFiServerSecure : public WiFiServer {
public: public:
WiFiServerSecure(IPAddress addr, uint16_t port); WiFiServerSecure(IPAddress addr, uint16_t port);
WiFiServerSecure(uint16_t port); WiFiServerSecure(uint16_t port = 22);
WiFiServerSecure(const WiFiServerSecure &rhs); WiFiServerSecure(const WiFiServerSecure &rhs);
virtual ~WiFiServerSecure(); virtual ~WiFiServerSecure();
...@@ -65,7 +65,7 @@ public: ...@@ -65,7 +65,7 @@ public:
// If awaiting connection available and authenticated (i.e. client cert), return it. // If awaiting connection available and authenticated (i.e. client cert), return it.
WiFiClientSecure accept(); // https://www.arduino.cc/en/Reference/EthernetServerAccept 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; WiFiServerSecure& operator=(const WiFiServerSecure&) = default;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment