@@ -331,23 +331,25 @@ int WiFiClient::getSocketOption(int level, int option, const void* value, size_t
331
331
return res;
332
332
}
333
333
334
-
335
- int WiFiClient::setTimeout (uint32_t seconds)
334
+ void WiFiClient::setTimeout (uint32_t seconds)
336
335
{
336
+ _lastReadTimeout = Client::getTimeout ();
337
+ _lastWriteTimeout = _lastReadTimeout;
337
338
Client::setTimeout (seconds * 1000 ); // This should be here?
338
339
_timeout = seconds * 1000 ;
339
- if (fd () >= 0 ) {
340
- struct timeval tv;
341
- tv.tv_sec = seconds;
342
- tv.tv_usec = 0 ;
343
- if (setSocketOption (SO_RCVTIMEO, (char *)&tv, sizeof (struct timeval )) < 0 ) {
344
- return -1 ;
345
- }
346
- return setSocketOption (SO_SNDTIMEO, (char *)&tv, sizeof (struct timeval ));
347
- }
348
- else {
349
- return 0 ;
350
- }
340
+
341
+ // if(fd() >= 0) {
342
+ // struct timeval tv;
343
+ // tv.tv_sec = seconds;
344
+ // tv.tv_usec = 0;
345
+ // if(setSocketOption(SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0) {
346
+ // return -1;
347
+ // }
348
+ // return setSocketOption(SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval));
349
+ // }
350
+ // else {
351
+ // return 0;
352
+ // }
351
353
}
352
354
353
355
int WiFiClient::setOption (int option, int *value)
@@ -418,6 +420,18 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size)
418
420
tv.tv_usec = WIFI_CLIENT_SELECT_TIMEOUT_US;
419
421
retry--;
420
422
423
+ if (_lastWriteTimeout != _timeout){
424
+ if (fd () >= 0 ){
425
+ struct timeval tv;
426
+ tv.tv_sec = _timeout/1000 ;
427
+ tv.tv_usec = 0 ;
428
+ if (setSocketOption (SO_SNDTIMEO, (char *)&tv, sizeof (struct timeval )) >= 0 )
429
+ {
430
+ _lastWriteTimeout = _timeout;
431
+ }
432
+ }
433
+ }
434
+
421
435
if (select (socketFileDescriptor + 1 , NULL , &set, NULL , &tv) < 0 ) {
422
436
return 0 ;
423
437
}
@@ -477,6 +491,18 @@ size_t WiFiClient::write(Stream &stream)
477
491
478
492
int WiFiClient::read (uint8_t *buf, size_t size)
479
493
{
494
+ if (_lastReadTimeout != _timeout){
495
+ if (fd () >= 0 ){
496
+ struct timeval tv;
497
+ tv.tv_sec = _timeout/1000 ;
498
+ tv.tv_usec = 0 ;
499
+ if (setSocketOption (SO_RCVTIMEO, (char *)&tv, sizeof (struct timeval )) >= 0 )
500
+ {
501
+ _lastReadTimeout = _timeout;
502
+ }
503
+ }
504
+ }
505
+
480
506
int res = -1 ;
481
507
if (_rxBuffer) {
482
508
res = _rxBuffer->read (buf, size);
0 commit comments