Skip to content

Commit b1193c2

Browse files
committed
Applied same changes for WifiClientSecure
1 parent e6e77ff commit b1193c2

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

libraries/WiFiClientSecure/src/WiFiClientSecure.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ size_t WiFiClientSecure::write(const uint8_t *buf, size_t size)
199199
if (!_connected) {
200200
return 0;
201201
}
202+
if(_lastWriteTimeout != _timeout){
203+
struct timeval timeout_tv;
204+
timeout_tv.tv_sec = _timeout/1000;
205+
timeout_tv.tv_usec = 0;
206+
if(setSocketOption(SO_SNDTIMEO, (char *)&timeout_tv, sizeof(struct timeval)) >= 0)
207+
{
208+
_lastWriteTimeout = _timeout;
209+
}
210+
}
211+
202212
int res = send_ssl_data(sslclient, buf, size);
203213
if (res < 0) {
204214
stop();
@@ -209,6 +219,18 @@ size_t WiFiClientSecure::write(const uint8_t *buf, size_t size)
209219

210220
int WiFiClientSecure::read(uint8_t *buf, size_t size)
211221
{
222+
if(_lastReadTimeout != _timeout){
223+
if(fd() >= 0){
224+
struct timeval timeout_tv;
225+
timeout_tv.tv_sec = _timeout/1000;
226+
timeout_tv.tv_usec = 0;
227+
if(setSocketOption(SO_RCVTIMEO, (char *)&timeout_tv, sizeof(struct timeval)) >= 0)
228+
{
229+
_lastReadTimeout = _timeout;
230+
}
231+
}
232+
}
233+
212234
int peeked = 0;
213235
int avail = available();
214236
if ((!buf && size) || avail <= 0) {
@@ -393,6 +415,8 @@ int WiFiClientSecure::setTimeout(uint32_t seconds)
393415
}
394416

395417
int WiFiClientSecure::fd() const
418+
419+
int WiFiClientSecure::setSocketOption(int option, char* value, size_t len)
396420
{
397421
return sslclient->socket;
398422
}

libraries/WiFiClientSecure/src/WiFiClientSecure.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class WiFiClientSecure : public WiFiClient
8282
bool getFingerprintSHA256(uint8_t sha256_result[32]) { return get_peer_fingerprint(sslclient, sha256_result); };
8383
int setTimeout(uint32_t seconds);
8484
int fd() const;
85+
int setSocketOption(int option, char* value, size_t len);
8586

8687
operator bool()
8788
{

0 commit comments

Comments
 (0)