@@ -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
@@ -24,48 +28,51 @@ void arduino::WiFiClient::getStatus() {
2428 }
2529}
2630
27-
28- int arduino::WiFiClient::connect (IPAddress ip, uint16_t port) {
29- }
30-
31- int arduino::WiFiClient::connect (const char *host, uint16_t port) {
31+ int arduino::WiFiClient::connect (SocketAddress socketAddress) {
3232 if (sock == NULL ) {
33- sock = new TCPSocket ();
34- (( TCPSocket*) sock)->open (WiFi.getNetwork ());
33+ sock = new TCPSocket ();
34+ static_cast < TCPSocket*>( sock)->open (WiFi.getNetwork ());
3535 }
3636 // sock->sigio(mbed::callback(this, &WiFiClient::getStatus));
3737 // 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- }
38+ sock->set_timeout (SOCKET_TIMEOUT);
39+ nsapi_error_t returnCode = static_cast <TCPSocket*>(sock)->connect (socketAddress);
40+ return returnCode == NSAPI_ERROR_OK ? 1 : 0 ;
4741}
4842
49- int arduino::WiFiClient::connectSSL (IPAddress ip, uint16_t port) {
43+ int arduino::WiFiClient::connect (IPAddress ip, uint16_t port) {
44+ return connect (WiFi.socketAddressFromIpAddress (ip, port));
5045}
5146
52- int arduino::WiFiClient::connectSSL (const char *host, uint16_t port) {
47+ int arduino::WiFiClient::connect (const char *host, uint16_t port) {
48+ SocketAddress socketAddress = SocketAddress ();
49+ socketAddress.set_port (port);
50+ WiFi.getNetwork ()->gethostbyname (host, &socketAddress);
51+ return connect (socketAddress);
52+ }
53+
54+ int arduino::WiFiClient::connectSSL (SocketAddress socketAddress){
5355 if (sock == NULL ) {
5456 sock = new TLSSocket ();
55- (( TLSSocket*) sock)->open (WiFi.getNetwork ());
57+ static_cast < TLSSocket*>( sock)->open (WiFi.getNetwork ());
5658 }
5759 if (beforeConnect) {
5860 beforeConnect ();
5961 }
60- sock->set_timeout (1000 );
61- SocketAddress addr (host, port);
62- WiFi.getNetwork ()->gethostbyname (host, &addr);
63- int ret = ((TLSSocket*)sock)->connect (addr);
64- if (ret == 0 ) {
65- return 1 ;
66- } else {
67- return 0 ;
68- }
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);
6976}
7077
7178size_t arduino::WiFiClient::write (uint8_t c) {
0 commit comments