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

WiFiServer - deprecate available(), use accept() everywhere (#8860)

esp8266 and esp32 server.available() is not implemented as documented
it is implemented like server.accept() is documented by Arduino
Co-authored-by: default avatarRodrigo Garcia <rodrigo.garcia@espressif.com>
parent 1e980bd7
...@@ -69,7 +69,7 @@ void setup(void) ...@@ -69,7 +69,7 @@ void setup(void)
void loop(void) void loop(void)
{ {
// Check if a client has connected // Check if a client has connected
WiFiClient client = server.available(); WiFiClient client = server.accept();
if (!client) { if (!client) {
return; return;
} }
......
...@@ -274,7 +274,7 @@ void WebServer::serveStatic(const char* uri, FS& fs, const char* path, const cha ...@@ -274,7 +274,7 @@ void WebServer::serveStatic(const char* uri, FS& fs, const char* path, const cha
void WebServer::handleClient() { void WebServer::handleClient() {
if (_currentStatus == HC_NONE) { if (_currentStatus == HC_NONE) {
_currentClient = _server.available(); _currentClient = _server.accept();
if (!_currentClient) { if (!_currentClient) {
if (_nullDelay) { if (_nullDelay) {
delay(1); delay(1);
......
...@@ -63,7 +63,7 @@ void setup() ...@@ -63,7 +63,7 @@ void setup()
} }
void loop(){ void loop(){
WiFiClient client = server.available(); // listen for incoming clients WiFiClient client = server.accept(); // listen for incoming clients
if (client) { // if you get a client, if (client) { // if you get a client,
Serial.println("New Client."); // print a message out the serial port Serial.println("New Client."); // print a message out the serial port
......
...@@ -48,7 +48,7 @@ void setup() { ...@@ -48,7 +48,7 @@ void setup() {
} }
void loop() { void loop() {
WiFiClient client = server.available(); // listen for incoming clients WiFiClient client = server.accept(); // listen for incoming clients
if (client) { // if you get a client, if (client) { // if you get a client,
Serial.println("New Client."); // print a message out the serial port Serial.println("New Client."); // print a message out the serial port
......
...@@ -78,7 +78,7 @@ void loop() { ...@@ -78,7 +78,7 @@ void loop() {
//find free/disconnected spot //find free/disconnected spot
if (!serverClients[i] || !serverClients[i].connected()){ if (!serverClients[i] || !serverClients[i].connected()){
if(serverClients[i]) serverClients[i].stop(); if(serverClients[i]) serverClients[i].stop();
serverClients[i] = server.available(); serverClients[i] = server.accept();
if (!serverClients[i]) Serial.println("available broken"); if (!serverClients[i]) Serial.println("available broken");
Serial.print("New client: "); Serial.print("New client: ");
Serial.print(i); Serial.print(' '); Serial.print(i); Serial.print(' ');
...@@ -88,7 +88,7 @@ void loop() { ...@@ -88,7 +88,7 @@ void loop() {
} }
if (i >= MAX_SRV_CLIENTS) { if (i >= MAX_SRV_CLIENTS) {
//no free/disconnected spot so reject //no free/disconnected spot so reject
server.available().stop(); server.accept().stop();
} }
} }
//check clients for data //check clients for data
......
...@@ -39,6 +39,10 @@ size_t WiFiServer::write(const uint8_t *data, size_t len){ ...@@ -39,6 +39,10 @@ size_t WiFiServer::write(const uint8_t *data, size_t len){
void WiFiServer::stopAll(){} void WiFiServer::stopAll(){}
WiFiClient WiFiServer::available(){ WiFiClient WiFiServer::available(){
return accept();
}
WiFiClient WiFiServer::accept(){
if(!_listening) if(!_listening)
return WiFiClient(); return WiFiClient();
int client_sock; int client_sock;
......
...@@ -45,8 +45,8 @@ class WiFiServer : public Server { ...@@ -45,8 +45,8 @@ class WiFiServer : public Server {
log_v("WiFiServer::WiFiServer(addr=%s, port=%d, ...)", addr.toString().c_str(), port); log_v("WiFiServer::WiFiServer(addr=%s, port=%d, ...)", addr.toString().c_str(), port);
} }
~WiFiServer(){ end();} ~WiFiServer(){ end();}
WiFiClient available(); WiFiClient available() __attribute__((deprecated("Renamed to accept().")));
WiFiClient accept(){return available();} WiFiClient accept();
void begin(uint16_t port=0); void begin(uint16_t port=0);
void begin(uint16_t port, int reuse_enable); void begin(uint16_t port, int reuse_enable);
void setNoDelay(bool nodelay); void setNoDelay(bool nodelay);
......
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