Skip to content

Commit 28e727d

Browse files
committed
Applied same changes for WifiClientSecure
1 parent 25b2062 commit 28e727d

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

libraries/WiFiClientSecure/src/WiFiClientSecure.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,16 @@ size_t WiFiClientSecure::write(const uint8_t *buf, size_t size)
185185
if (!_connected) {
186186
return 0;
187187
}
188+
if(_lastWriteTimeout != _timeout){
189+
struct timeval timeout_tv;
190+
timeout_tv.tv_sec = _timeout/1000;
191+
timeout_tv.tv_usec = 0;
192+
if(setSocketOption(SO_SNDTIMEO, (char *)&timeout_tv, sizeof(struct timeval)) >= 0)
193+
{
194+
_lastWriteTimeout = _timeout;
195+
}
196+
}
197+
188198
int res = send_ssl_data(sslclient, buf, size);
189199
if (res < 0) {
190200
stop();
@@ -195,6 +205,18 @@ size_t WiFiClientSecure::write(const uint8_t *buf, size_t size)
195205

196206
int WiFiClientSecure::read(uint8_t *buf, size_t size)
197207
{
208+
if(_lastReadTimeout != _timeout){
209+
if(fd() >= 0){
210+
struct timeval timeout_tv;
211+
timeout_tv.tv_sec = _timeout/1000;
212+
timeout_tv.tv_usec = 0;
213+
if(setSocketOption(SO_RCVTIMEO, (char *)&timeout_tv, sizeof(struct timeval)) >= 0)
214+
{
215+
_lastReadTimeout = _timeout;
216+
}
217+
}
218+
}
219+
198220
int peeked = 0;
199221
int avail = available();
200222
if ((!buf && size) || avail <= 0) {
@@ -360,22 +382,7 @@ void WiFiClientSecure::setAlpnProtocols(const char **alpn_protos)
360382
{
361383
_alpn_protos = alpn_protos;
362384
}
363-
int WiFiClientSecure::setTimeout(uint32_t seconds)
364-
{
365-
_timeout = seconds * 1000;
366-
if (sslclient->socket >= 0) {
367-
struct timeval tv;
368-
tv.tv_sec = seconds;
369-
tv.tv_usec = 0;
370-
if(setSocketOption(SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0) {
371-
return -1;
372-
}
373-
return setSocketOption(SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval));
374-
}
375-
else {
376-
return 0;
377-
}
378-
}
385+
379386
int WiFiClientSecure::setSocketOption(int option, char* value, size_t len)
380387
{
381388
int res = setsockopt(sslclient->socket, SOL_SOCKET, option, value, len);

libraries/WiFiClientSecure/src/WiFiClientSecure.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ class WiFiClientSecure : public WiFiClient
7979
void setAlpnProtocols(const char **alpn_protos);
8080
const mbedtls_x509_crt* getPeerCertificate() { return mbedtls_ssl_get_peer_cert(&sslclient->ssl_ctx); };
8181
bool getFingerprintSHA256(uint8_t sha256_result[32]) { return get_peer_fingerprint(sslclient, sha256_result); };
82-
int setTimeout(uint32_t seconds);
8382
int setSocketOption(int option, char* value, size_t len);
8483

8584
operator bool()

0 commit comments

Comments
 (0)