diff --git a/src/WiFiClient.cpp b/src/WiFiClient.cpp index 43e9cea8..641c5841 100644 --- a/src/WiFiClient.cpp +++ b/src/WiFiClient.cpp @@ -18,6 +18,7 @@ */ #include "utility/WiFiSocket.h" +#include "utility/tcp_states.h" #include "WiFi101.h" #include "WiFiClient.h" @@ -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() diff --git a/src/WiFiServer.cpp b/src/WiFiServer.cpp index fa72ddca..2e7a0aa8 100644 --- a/src/WiFiServer.cpp +++ b/src/WiFiServer.cpp @@ -18,6 +18,7 @@ */ #include "utility/WiFiSocket.h" +#include "utility/tcp_states.h" #include "WiFiClient.h" #include "WiFiServer.h" @@ -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) diff --git a/src/utility/tcp_states.h b/src/utility/tcp_states.h new file mode 100644 index 00000000..b3e48f2f --- /dev/null +++ b/src/utility/tcp_states.h @@ -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