@@ -19,8 +19,10 @@ void arduino::EthernetClient::setSocket(Socket* _sock) {
19
19
}
20
20
21
21
void arduino::EthernetClient::getStatus () {
22
- if (sock == nullptr )
22
+ if (sock == nullptr ) {
23
+ _status = false ;
23
24
return ;
25
+ }
24
26
25
27
uint8_t data[256 ];
26
28
int ret = sock->recv (data, rxBuffer.availableForStore ());
@@ -33,7 +35,7 @@ void arduino::EthernetClient::getStatus() {
33
35
}
34
36
35
37
int arduino::EthernetClient::connect (SocketAddress socketAddress) {
36
- if (sock == NULL ) {
38
+ if (sock == nullptr ) {
37
39
sock = new TCPSocket ();
38
40
if (static_cast <TCPSocket*>(sock)->open (Ethernet.getNetwork ()) != NSAPI_ERROR_OK){
39
41
return 0 ;
@@ -62,7 +64,7 @@ int arduino::EthernetClient::connect(const char *host, uint16_t port) {
62
64
}
63
65
64
66
int arduino::EthernetClient::connectSSL (SocketAddress socketAddress){
65
- if (sock == NULL ) {
67
+ if (sock == nullptr ) {
66
68
sock = new TLSSocket ();
67
69
if (static_cast <TLSSocket*>(sock)->open (Ethernet.getNetwork ()) != NSAPI_ERROR_OK){
68
70
return 0 ;
@@ -88,11 +90,17 @@ int arduino::EthernetClient::connectSSL(const char *host, uint16_t port) {
88
90
}
89
91
90
92
size_t arduino::EthernetClient::write (uint8_t c) {
91
- sock->send (&c, 1 );
93
+ if (sock == nullptr )
94
+ return -1 ;
95
+ auto ret = sock->send (&c, 1 );
96
+ return ret;
92
97
}
93
98
94
99
size_t arduino::EthernetClient::write (const uint8_t *buf, size_t size) {
95
- sock->send (buf, size);
100
+ if (sock == nullptr )
101
+ return -1 ;
102
+ auto ret = sock->send (buf, size);
103
+ return ret;
96
104
}
97
105
98
106
int arduino::EthernetClient::available () {
@@ -137,15 +145,16 @@ void arduino::EthernetClient::flush() {
137
145
}
138
146
139
147
void arduino::EthernetClient::stop () {
140
- if (sock != NULL ) {
148
+ if (sock != nullptr ) {
141
149
sock->close ();
142
- sock = NULL ;
143
- _status = false ;
150
+ sock = nullptr ;
144
151
}
152
+ _status = false ;
145
153
}
146
154
147
155
uint8_t arduino::EthernetClient::connected () {
148
- return _status == true ;
156
+ getStatus ();
157
+ return _status;
149
158
}
150
159
151
160
IPAddress arduino::EthernetClient::remoteIP () {
0 commit comments