File tree 2 files changed +20
-8
lines changed
2 files changed +20
-8
lines changed Original file line number Diff line number Diff line change 4
4
#define SOCKET_TIMEOUT 1000
5
5
#endif
6
6
7
- arduino::EthernetClient::EthernetClient () {
7
+ arduino::EthernetClient::EthernetClient ()
8
+ : _status(false )
9
+ {
8
10
}
9
11
10
12
uint8_t arduino::EthernetClient::status () {
11
13
return _status;
12
14
}
13
15
16
+ void arduino::EthernetClient::setSocket (Socket* _sock) {
17
+ sock = _sock;
18
+ _status = true ;
19
+ }
20
+
14
21
void arduino::EthernetClient::getStatus () {
22
+ if (sock == nullptr )
23
+ return ;
24
+
15
25
uint8_t data[256 ];
16
26
int ret = sock->recv (data, rxBuffer.availableForStore ());
17
27
for (int i = 0 ; i < ret; i++) {
18
28
rxBuffer.store_char (data[i]);
19
29
}
20
30
if (ret < 0 && ret != NSAPI_ERROR_WOULD_BLOCK) {
21
- _status = LinkOFF ;
31
+ _status = false ;
22
32
}
23
33
}
24
34
@@ -34,7 +44,10 @@ int arduino::EthernetClient::connect(SocketAddress socketAddress) {
34
44
address = socketAddress;
35
45
sock->set_timeout (SOCKET_TIMEOUT);
36
46
nsapi_error_t returnCode = static_cast <TCPSocket*>(sock)->connect (socketAddress);
37
- return returnCode == NSAPI_ERROR_OK ? 1 : 0 ;
47
+ auto ret = returnCode == NSAPI_ERROR_OK ? 1 : 0 ;
48
+ if (ret)
49
+ _status = true ;
50
+ return ret;
38
51
}
39
52
40
53
int arduino::EthernetClient::connect (IPAddress ip, uint16_t port) {
@@ -127,11 +140,12 @@ void arduino::EthernetClient::stop() {
127
140
if (sock != NULL ) {
128
141
sock->close ();
129
142
sock = NULL ;
143
+ _status = false ;
130
144
}
131
145
}
132
146
133
147
uint8_t arduino::EthernetClient::connected () {
134
- return _status != LinkOFF ;
148
+ return _status == true ;
135
149
}
136
150
137
151
IPAddress arduino::EthernetClient::remoteIP () {
Original file line number Diff line number Diff line change @@ -57,9 +57,7 @@ class EthernetClient : public arduino::Client {
57
57
return sock != NULL ;
58
58
}
59
59
60
- void setSocket (Socket* _sock) {
61
- sock = _sock;
62
- }
60
+ void setSocket (Socket* _sock);
63
61
64
62
IPAddress remoteIP ();
65
63
uint16_t remotePort ();
@@ -78,7 +76,7 @@ class EthernetClient : public arduino::Client {
78
76
static uint16_t _srcport;
79
77
Socket* sock;
80
78
RingBufferN<256 > rxBuffer;
81
- uint8_t _status;
79
+ bool _status;
82
80
mbed::Callback<int (void )> beforeConnect;
83
81
SocketAddress address;
84
82
You can’t perform that action at this time.
0 commit comments