@@ -24,26 +24,27 @@ void arduino::WiFiClient::getStatus() {
24
24
}
25
25
}
26
26
27
-
28
- int arduino::WiFiClient::connect (IPAddress ip, uint16_t port) {
29
- }
30
-
31
- int arduino::WiFiClient::connect (const char *host, uint16_t port) {
27
+ int arduino::WiFiClient::connect (SocketAddress socketAddress) {
32
28
if (sock == NULL ) {
33
- sock = new TCPSocket ();
34
- (( TCPSocket*) sock)->open (WiFi.getNetwork ());
29
+ sock = new TCPSocket ();
30
+ static_cast < TCPSocket*>( sock)->open (WiFi.getNetwork ());
35
31
}
36
32
// sock->sigio(mbed::callback(this, &WiFiClient::getStatus));
37
33
// sock->set_blocking(false);
38
- sock->set_timeout (1000 );
39
- SocketAddress addr (host, port);
40
- WiFi.getNetwork ()->gethostbyname (host, &addr);
41
- int ret = ((TCPSocket*)sock)->connect (addr);
42
- if (ret == 0 ) {
43
- return 1 ;
44
- } else {
45
- return 0 ;
46
- }
34
+ sock->set_timeout (1000 );
35
+ nsapi_error_t returnCode = static_cast <TCPSocket*>(sock)->connect (socketAddress);
36
+ return returnCode == NSAPI_ERROR_OK ? 1 : 0 ;
37
+ }
38
+
39
+ int arduino::WiFiClient::connect (IPAddress ip, uint16_t port) {
40
+ return connect (WiFi.socketAddressFromIpAddress (ip, port));
41
+ }
42
+
43
+ int arduino::WiFiClient::connect (const char *host, uint16_t port) {
44
+ SocketAddress socketAddress = SocketAddress ();
45
+ socketAddress.set_port (port);
46
+ WiFi.getNetwork ()->gethostbyname (host, &socketAddress);
47
+ return connect (socketAddress);
47
48
}
48
49
49
50
int arduino::WiFiClient::connectSSL (IPAddress ip, uint16_t port) {
0 commit comments