Skip to content

Commit 9172c17

Browse files
committed
Manage sockets already connected
1 parent cf184fd commit 9172c17

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

libraries/Ethernet/src/EthernetClient.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,15 @@ int arduino::EthernetClient::connect(SocketAddress socketAddress) {
4646
address = socketAddress;
4747
sock->set_timeout(SOCKET_TIMEOUT);
4848
nsapi_error_t returnCode = static_cast<TCPSocket*>(sock)->connect(socketAddress);
49-
auto ret = returnCode == NSAPI_ERROR_OK ? 1 : 0;
50-
if (ret)
49+
int ret = 0;
50+
switch (returnCode) {
51+
case NSAPI_ERROR_IS_CONNECTED:
52+
case NSAPI_ERROR_OK: {
53+
ret = 1;
54+
break;
55+
}
56+
}
57+
if (ret == 1)
5158
_status = true;
5259
return ret;
5360
}
@@ -75,7 +82,18 @@ int arduino::EthernetClient::connectSSL(SocketAddress socketAddress){
7582
}
7683
sock->set_timeout(SOCKET_TIMEOUT);
7784
nsapi_error_t returnCode = static_cast<TLSSocket*>(sock)->connect(socketAddress);
78-
return returnCode == NSAPI_ERROR_OK ? 1 : 0;
85+
int ret = 0;
86+
switch (returnCode) {
87+
case NSAPI_ERROR_IS_CONNECTED:
88+
case NSAPI_ERROR_OK: {
89+
ret = 1;
90+
break;
91+
}
92+
}
93+
if (ret == 1)
94+
_status = true;
95+
96+
return ret;
7997
}
8098

8199
int arduino::EthernetClient::connectSSL(IPAddress ip, uint16_t port) {

0 commit comments

Comments
 (0)