Skip to content

Commit 96457bc

Browse files
authored
Merge pull request #148 from JAndrassy/wifis3_client_con_timeout
WiFiS3 client connect timeout
2 parents eb13557 + bd2c159 commit 96457bc

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

Diff for: libraries/WiFiS3/src/WiFiClient.cpp

+8-10
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,8 @@ void WiFiClient::getSocket() {
3939

4040
/* -------------------------------------------------------------------------- */
4141
int WiFiClient::connect(IPAddress ip, uint16_t port){
42-
/* -------------------------------------------------------------------------- */
43-
getSocket();
44-
if(_sock >= 0) {
45-
string res = "";
46-
modem.begin();
47-
if(modem.write(string(PROMPT(_CLIENTCONNECTIP)),res, "%s%d,%s,%d\r\n" , CMD_WRITE(_CLIENTCONNECTIP), _sock, ip.toString().c_str(), port)) {
48-
return 1;
49-
}
50-
}
51-
return 0;
42+
/* -------------------------------------------------------------------------- */
43+
return connect(ip.toString().c_str(), port);
5244
}
5345

5446
/* -------------------------------------------------------------------------- */
@@ -58,9 +50,15 @@ int WiFiClient::connect(const char *host, uint16_t port){
5850
if(_sock >= 0) {
5951
string res = "";
6052
modem.begin();
53+
if (_connectionTimeout) {
54+
if(modem.write(string(PROMPT(_CLIENTCONNECT)),res, "%s%d,%s,%d,%d\r\n" , CMD_WRITE(_CLIENTCONNECT), _sock, host,port, _connectionTimeout)) {
55+
return 1;
56+
}
57+
} else {
6158
if(modem.write(string(PROMPT(_CLIENTCONNECTNAME)),res, "%s%d,%s,%d\r\n" , CMD_WRITE(_CLIENTCONNECTNAME), _sock, host,port)) {
6259
return 1;
6360
}
61+
}
6462
}
6563
return 0;
6664
}

Diff for: libraries/WiFiS3/src/WiFiClient.h

+5
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,17 @@ class WiFiClient : public Client {
6262
virtual IPAddress remoteIP();
6363
virtual uint16_t remotePort();
6464

65+
void setConnectionTimeout(int timeout) {
66+
_connectionTimeout = timeout;
67+
}
68+
6569
friend class WiFiServer;
6670

6771
using Print::write;
6872

6973
protected:
7074
int _sock;
75+
int _connectionTimeout = 0;
7176
void getSocket();
7277
std::shared_ptr<FifoBuffer<uint8_t,RX_BUFFER_DIM>> rx_buffer;
7378
int _read();

Diff for: libraries/WiFiS3/src/WiFiSSLClient.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,7 @@ void WiFiSSLClient::getSocket() {
2929
/* -------------------------------------------------------------------------- */
3030
int WiFiSSLClient::connect(IPAddress ip, uint16_t port) {
3131
/* -------------------------------------------------------------------------- */
32-
getSocket();
33-
34-
string res = "";
35-
if(modem.write(string(PROMPT(_SSLCLIENTCONNECTIP)),res, "%s%d,%s,%d\r\n" , CMD_WRITE(_SSLCLIENTCONNECTIP), _sock, ip.toString(), port)) {
36-
return 1;
37-
}
38-
return 0;
32+
return connect(ip.toString().c_str(), port);
3933
}
4034

4135
/* -------------------------------------------------------------------------- */
@@ -46,9 +40,15 @@ int WiFiSSLClient::connect(const char* host, uint16_t port) {
4640
setCACert();
4741
}
4842
string res = "";
43+
if (_connectionTimeout) {
44+
if(modem.write(string(PROMPT(_SSLCLIENTCONNECT)),res, "%s%d,%s,%d,%d\r\n" , CMD_WRITE(_SSLCLIENTCONNECT), _sock, host,port, _connectionTimeout)) {
45+
return 1;
46+
}
47+
} else {
4948
if(modem.write(string(PROMPT(_SSLCLIENTCONNECTNAME)),res, "%s%d,%s,%d\r\n" , CMD_WRITE(_SSLCLIENTCONNECTNAME), _sock, host, port)) {
5049
return 1;
5150
}
51+
}
5252
return 0;
5353
}
5454

0 commit comments

Comments
 (0)