@@ -185,6 +185,16 @@ size_t WiFiClientSecure::write(const uint8_t *buf, size_t size)
185
185
if (!_connected) {
186
186
return 0 ;
187
187
}
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
+
188
198
int res = send_ssl_data (sslclient, buf, size);
189
199
if (res < 0 ) {
190
200
stop ();
@@ -195,6 +205,18 @@ size_t WiFiClientSecure::write(const uint8_t *buf, size_t size)
195
205
196
206
int WiFiClientSecure::read (uint8_t *buf, size_t size)
197
207
{
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
+
198
220
int peeked = 0 ;
199
221
int avail = available ();
200
222
if ((!buf && size) || avail <= 0 ) {
@@ -360,22 +382,7 @@ void WiFiClientSecure::setAlpnProtocols(const char **alpn_protos)
360
382
{
361
383
_alpn_protos = alpn_protos;
362
384
}
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
+
379
386
int WiFiClientSecure::setSocketOption (int option, char * value, size_t len)
380
387
{
381
388
int res = setsockopt (sslclient->socket , SOL_SOCKET, option, value, len);
0 commit comments