@@ -6,6 +6,10 @@ extern WiFiClass WiFi;
6
6
#define WIFI_TCP_BUFFER_SIZE 1508
7
7
#endif
8
8
9
+ #ifndef SOCKET_TIMEOUT
10
+ #define SOCKET_TIMEOUT 1000
11
+ #endif
12
+
9
13
arduino::WiFiClient::WiFiClient () {
10
14
}
11
15
@@ -31,7 +35,7 @@ int arduino::WiFiClient::connect(SocketAddress socketAddress) {
31
35
}
32
36
// sock->sigio(mbed::callback(this, &WiFiClient::getStatus));
33
37
// sock->set_blocking(false);
34
- sock->set_timeout (1000 );
38
+ sock->set_timeout (SOCKET_TIMEOUT );
35
39
nsapi_error_t returnCode = static_cast <TCPSocket*>(sock)->connect (socketAddress);
36
40
return returnCode == NSAPI_ERROR_OK ? 1 : 0 ;
37
41
}
@@ -47,26 +51,28 @@ int arduino::WiFiClient::connect(const char *host, uint16_t port) {
47
51
return connect (socketAddress);
48
52
}
49
53
50
- int arduino::WiFiClient::connectSSL (IPAddress ip, uint16_t port) {
51
- }
52
-
53
- int arduino::WiFiClient::connectSSL (const char *host, uint16_t port) {
54
+ int arduino::WiFiClient::connectSSL (SocketAddress socketAddress){
54
55
if (sock == NULL ) {
55
56
sock = new TLSSocket ();
56
- (( TLSSocket*) sock)->open (WiFi.getNetwork ());
57
+ static_cast < TLSSocket*>( sock)->open (WiFi.getNetwork ());
57
58
}
58
59
if (beforeConnect) {
59
60
beforeConnect ();
60
61
}
61
- sock->set_timeout (1000 );
62
- SocketAddress addr (host, port);
63
- WiFi.getNetwork ()->gethostbyname (host, &addr);
64
- int ret = ((TLSSocket*)sock)->connect (addr);
65
- if (ret == 0 ) {
66
- return 1 ;
67
- } else {
68
- return 0 ;
69
- }
62
+ sock->set_timeout (SOCKET_TIMEOUT);
63
+ nsapi_error_t returnCode = static_cast <TLSSocket*>(sock)->connect (socketAddress);
64
+ return returnCode == NSAPI_ERROR_OK ? 1 : 0 ;
65
+ }
66
+
67
+ int arduino::WiFiClient::connectSSL (IPAddress ip, uint16_t port) {
68
+ return connectSSL (WiFi.socketAddressFromIpAddress (ip, port));
69
+ }
70
+
71
+ int arduino::WiFiClient::connectSSL (const char *host, uint16_t port) {
72
+ SocketAddress socketAddress = SocketAddress ();
73
+ socketAddress.set_port (port);
74
+ WiFi.getNetwork ()->gethostbyname (host, &socketAddress);
75
+ return connectSSL (socketAddress);
70
76
}
71
77
72
78
size_t arduino::WiFiClient::write (uint8_t c) {
0 commit comments