Skip to content

Commit 61b05ac

Browse files
committed
WiFiClient and WiFiServer status() method implementation
1 parent 1634ec2 commit 61b05ac

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/WiFiClient.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include "utility/WiFiSocket.h"
21+
#include "utility/tcp_states.h"
2122

2223
#include "WiFi101.h"
2324
#include "WiFiClient.h"
@@ -190,8 +191,9 @@ uint8_t WiFiClient::connected()
190191

191192
uint8_t WiFiClient::status()
192193
{
193-
// Deprecated.
194-
return 0;
194+
if (_socket != -1 && WiFiSocket.connected(_socket))
195+
return ESTABLISHED;
196+
return CLOSED;
195197
}
196198

197199
WiFiClient::operator bool()

src/WiFiServer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include "utility/WiFiSocket.h"
21+
#include "utility/tcp_states.h"
2122

2223
#include "WiFiClient.h"
2324
#include "WiFiServer.h"
@@ -102,8 +103,9 @@ WiFiClient WiFiServer::available(uint8_t* status)
102103
}
103104

104105
uint8_t WiFiServer::status() {
105-
// Deprecated.
106-
return 0;
106+
if (_socket != -1 && WiFiSocket.listening(_socket))
107+
return LISTEN;
108+
return CLOSED;
107109
}
108110

109111
size_t WiFiServer::write(uint8_t b)

src/utility/tcp_states.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef TCP_STATES_H
2+
#define TCP_STATES_H
3+
4+
// common constants for client.state() return values
5+
enum tcp_state {
6+
CLOSED = 0,
7+
LISTEN = 1,
8+
SYN_SENT = 2,
9+
SYN_RCVD = 3,
10+
ESTABLISHED = 4,
11+
FIN_WAIT_1 = 5,
12+
FIN_WAIT_2 = 6,
13+
CLOSE_WAIT = 7,
14+
CLOSING = 8,
15+
LAST_ACK = 9,
16+
TIME_WAIT = 10
17+
};
18+
19+
#endif

0 commit comments

Comments
 (0)