@@ -35,10 +35,10 @@ extern "C" {
35
35
36
36
uint16_t WiFiClient::_srcport = 1024 ;
37
37
38
- WiFiClient::WiFiClient () : _sock(NO_SOCKET_AVAIL) {
38
+ WiFiClient::WiFiClient () : _sock(NO_SOCKET_AVAIL), _connect_timeout( 10000 ) {
39
39
}
40
40
41
- WiFiClient::WiFiClient (uint8_t sock) : _sock(sock) {
41
+ WiFiClient::WiFiClient (uint8_t sock) : _sock(sock), _connect_timeout( 10000 ) {
42
42
}
43
43
44
44
int WiFiClient::connect (const char * host, uint16_t port) {
@@ -63,8 +63,7 @@ int WiFiClient::connect(IPAddress ip, uint16_t port) {
63
63
64
64
unsigned long start = millis ();
65
65
66
- // wait 4 second for the connection to close
67
- while (!connected () && millis () - start < 10000 )
66
+ while (!connected () && millis () - start < _connect_timeout)
68
67
delay (1 );
69
68
70
69
if (!connected ())
@@ -92,8 +91,7 @@ int WiFiClient::connectSSL(IPAddress ip, uint16_t port)
92
91
93
92
unsigned long start = millis ();
94
93
95
- // wait 4 second for the connection to close
96
- while (!connected () && millis () - start < 10000 )
94
+ while (!connected () && millis () - start < _connect_timeout)
97
95
delay (1 );
98
96
99
97
if (!connected ())
@@ -121,8 +119,7 @@ int WiFiClient::connectSSL(const char *host, uint16_t port)
121
119
122
120
unsigned long start = millis ();
123
121
124
- // wait 4 second for the connection to close
125
- while (!connected () && millis () - start < 10000 )
122
+ while (!connected () && millis () - start < _connect_timeout)
126
123
delay (1 );
127
124
128
125
if (!connected ())
@@ -272,3 +269,8 @@ uint16_t WiFiClient::remotePort()
272
269
uint16_t port = (_remotePort[0 ]<<8 )+_remotePort[1 ];
273
270
return port;
274
271
}
272
+
273
+ void WiFiClient::setConnectTimeout (unsigned long timeout)
274
+ {
275
+ _connect_timeout = timeout;
276
+ }
0 commit comments