Skip to content

Commit

Permalink
WiFiClient and WiFiServer status() method implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
JAndrassy committed Oct 6, 2023
1 parent 1634ec2 commit 61b05ac
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include "utility/WiFiSocket.h"
#include "utility/tcp_states.h"

#include "WiFi101.h"
#include "WiFiClient.h"
Expand Down Expand Up @@ -190,8 +191,9 @@ uint8_t WiFiClient::connected()

uint8_t WiFiClient::status()
{
// Deprecated.
return 0;
if (_socket != -1 && WiFiSocket.connected(_socket))
return ESTABLISHED;
return CLOSED;
}

WiFiClient::operator bool()
Expand Down
6 changes: 4 additions & 2 deletions src/WiFiServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include "utility/WiFiSocket.h"
#include "utility/tcp_states.h"

#include "WiFiClient.h"
#include "WiFiServer.h"
Expand Down Expand Up @@ -102,8 +103,9 @@ WiFiClient WiFiServer::available(uint8_t* status)
}

uint8_t WiFiServer::status() {
// Deprecated.
return 0;
if (_socket != -1 && WiFiSocket.listening(_socket))
return LISTEN;
return CLOSED;
}

size_t WiFiServer::write(uint8_t b)
Expand Down
19 changes: 19 additions & 0 deletions src/utility/tcp_states.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef TCP_STATES_H
#define TCP_STATES_H

// common constants for client.state() return values
enum tcp_state {
CLOSED = 0,
LISTEN = 1,
SYN_SENT = 2,
SYN_RCVD = 3,
ESTABLISHED = 4,
FIN_WAIT_1 = 5,
FIN_WAIT_2 = 6,
CLOSE_WAIT = 7,
CLOSING = 8,
LAST_ACK = 9,
TIME_WAIT = 10
};

#endif

0 comments on commit 61b05ac

Please sign in to comment.