Skip to content

Commit cc4d69e

Browse files
committed
Improve error handling of connect functions
1 parent e36aaa9 commit cc4d69e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

libraries/WiFi/src/WiFiClient.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ void arduino::WiFiClient::getStatus() {
3131
int arduino::WiFiClient::connect(SocketAddress socketAddress) {
3232
if (sock == NULL) {
3333
sock = new TCPSocket();
34-
static_cast<TCPSocket*>(sock)->open(WiFi.getNetwork());
34+
if(static_cast<TCPSocket*>(sock)->open(WiFi.getNetwork()) != NSAPI_ERROR_OK){
35+
return 0;
36+
}
3537
}
3638
//sock->sigio(mbed::callback(this, &WiFiClient::getStatus));
3739
//sock->set_blocking(false);
@@ -54,7 +56,9 @@ int arduino::WiFiClient::connect(const char *host, uint16_t port) {
5456
int arduino::WiFiClient::connectSSL(SocketAddress socketAddress){
5557
if (sock == NULL) {
5658
sock = new TLSSocket();
57-
static_cast<TLSSocket*>(sock)->open(WiFi.getNetwork());
59+
if(static_cast<TLSSocket*>(sock)->open(WiFi.getNetwork()) != NSAPI_ERROR_OK){
60+
return 0;
61+
}
5862
}
5963
if (beforeConnect) {
6064
beforeConnect();

0 commit comments

Comments
 (0)