Skip to content

Commit

Permalink
WiFiServer - deprecate available(), use accept() everywhere (espressi…
Browse files Browse the repository at this point in the history
…f#8860)

esp8266 and esp32 server.available() is not implemented as documented
it is implemented like server.accept() is documented by Arduino

Co-authored-by: Rodrigo Garcia <[email protected]>
  • Loading branch information
JAndrassy and SuGlider authored Nov 27, 2023
1 parent 1e980bd commit 990e3d5
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void setup(void)
void loop(void)
{
// Check if a client has connected
WiFiClient client = server.available();
WiFiClient client = server.accept();
if (!client) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/WebServer/src/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void WebServer::serveStatic(const char* uri, FS& fs, const char* path, const cha

void WebServer::handleClient() {
if (_currentStatus == HC_NONE) {
_currentClient = _server.available();
_currentClient = _server.accept();
if (!_currentClient) {
if (_nullDelay) {
delay(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void setup()
}

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,
Serial.println("New Client."); // print a message out the serial port
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void setup() {
}

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,
Serial.println("New Client."); // print a message out the serial port
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void loop() {
//find free/disconnected spot
if (!serverClients[i] || !serverClients[i].connected()){
if(serverClients[i]) serverClients[i].stop();
serverClients[i] = server.available();
serverClients[i] = server.accept();
if (!serverClients[i]) Serial.println("available broken");
Serial.print("New client: ");
Serial.print(i); Serial.print(' ');
Expand All @@ -88,7 +88,7 @@ void loop() {
}
if (i >= MAX_SRV_CLIENTS) {
//no free/disconnected spot so reject
server.available().stop();
server.accept().stop();
}
}
//check clients for data
Expand Down
4 changes: 4 additions & 0 deletions libraries/WiFi/src/WiFiServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ size_t WiFiServer::write(const uint8_t *data, size_t len){
void WiFiServer::stopAll(){}

WiFiClient WiFiServer::available(){
return accept();
}

WiFiClient WiFiServer::accept(){
if(!_listening)
return WiFiClient();
int client_sock;
Expand Down
4 changes: 2 additions & 2 deletions libraries/WiFi/src/WiFiServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class WiFiServer : public Server {
log_v("WiFiServer::WiFiServer(addr=%s, port=%d, ...)", addr.toString().c_str(), port);
}
~WiFiServer(){ end();}
WiFiClient available();
WiFiClient accept(){return available();}
WiFiClient available() __attribute__((deprecated("Renamed to accept().")));
WiFiClient accept();
void begin(uint16_t port=0);
void begin(uint16_t port, int reuse_enable);
void setNoDelay(bool nodelay);
Expand Down

0 comments on commit 990e3d5

Please sign in to comment.