Skip to content

Commit 5c2cd48

Browse files
c1728p9simonbutcher
authored andcommitted
Check return value of connect to trap sooner (#19)
Check the return value of connect and error if it did not succeed. This make socket errors more obvious since the TLS handshake has not started at this point.
1 parent 3ddf854 commit 5c2cd48

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

tls-client/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,12 @@ class HelloHTTPS {
207207

208208
/* Connect to the server */
209209
mbedtls_printf("Connecting with %s\r\n", _domain);
210-
_tcpsocket->connect( _domain, _port );
210+
ret = _tcpsocket->connect(_domain, _port);
211+
if (ret != NSAPI_ERROR_OK) {
212+
mbedtls_printf("Failed to connect\r\n");
213+
onError(_tcpsocket, -1);
214+
return;
215+
}
211216

212217
/* Start the handshake, the rest will be done in onReceive() */
213218
mbedtls_printf("Starting the TLS handshake...\r\n");

0 commit comments

Comments
 (0)