@@ -6,6 +6,10 @@ extern WiFiClass WiFi;
66#define WIFI_TCP_BUFFER_SIZE 1508
77#endif
88
9+ #ifndef SOCKET_TIMEOUT
10+ #define SOCKET_TIMEOUT 1000
11+ #endif
12+
913arduino::WiFiClient::WiFiClient () {
1014}
1115
@@ -31,7 +35,7 @@ int arduino::WiFiClient::connect(SocketAddress socketAddress) {
3135 }
3236 // sock->sigio(mbed::callback(this, &WiFiClient::getStatus));
3337 // sock->set_blocking(false);
34- sock->set_timeout (1000 );
38+ sock->set_timeout (SOCKET_TIMEOUT );
3539 nsapi_error_t returnCode = static_cast <TCPSocket*>(sock)->connect (socketAddress);
3640 return returnCode == NSAPI_ERROR_OK ? 1 : 0 ;
3741}
@@ -47,26 +51,28 @@ int arduino::WiFiClient::connect(const char *host, uint16_t port) {
4751 return connect (socketAddress);
4852}
4953
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){
5455 if (sock == NULL ) {
5556 sock = new TLSSocket ();
56- (( TLSSocket*) sock)->open (WiFi.getNetwork ());
57+ static_cast < TLSSocket*>( sock)->open (WiFi.getNetwork ());
5758 }
5859 if (beforeConnect) {
5960 beforeConnect ();
6061 }
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);
7076}
7177
7278size_t arduino::WiFiClient::write (uint8_t c) {
0 commit comments