@@ -310,22 +310,25 @@ int WiFiClient::setSocketOption(int option, char* value, size_t len)
310310 return res;
311311}
312312
313- int WiFiClient::setTimeout (uint32_t seconds)
313+ void WiFiClient::setTimeout (uint32_t seconds)
314314{
315+ _lastReadTimeout = Client::getTimeout ();
316+ _lastWriteTimeout = _lastReadTimeout;
315317 Client::setTimeout (seconds * 1000 ); // This should be here?
316318 _timeout = seconds * 1000 ;
317- if (fd () >= 0 ) {
318- struct timeval tv;
319- tv.tv_sec = seconds;
320- tv.tv_usec = 0 ;
321- if (setSocketOption (SO_RCVTIMEO, (char *)&tv, sizeof (struct timeval )) < 0 ) {
322- return -1 ;
323- }
324- return setSocketOption (SO_SNDTIMEO, (char *)&tv, sizeof (struct timeval ));
325- }
326- else {
327- return 0 ;
328- }
319+
320+ // if(fd() >= 0) {
321+ // struct timeval tv;
322+ // tv.tv_sec = seconds;
323+ // tv.tv_usec = 0;
324+ // if(setSocketOption(SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0) {
325+ // return -1;
326+ // }
327+ // return setSocketOption(SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval));
328+ // }
329+ // else {
330+ // return 0;
331+ // }
329332}
330333
331334int WiFiClient::setOption (int option, int *value)
@@ -400,6 +403,18 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size)
400403 tv.tv_usec = WIFI_CLIENT_SELECT_TIMEOUT_US;
401404 retry--;
402405
406+ if (_lastWriteTimeout != _timeout){
407+ if (fd () >= 0 ){
408+ struct timeval tv;
409+ tv.tv_sec = _timeout/1000 ;
410+ tv.tv_usec = 0 ;
411+ if (setSocketOption (SO_SNDTIMEO, (char *)&tv, sizeof (struct timeval )) >= 0 )
412+ {
413+ _lastWriteTimeout = _timeout;
414+ }
415+ }
416+ }
417+
403418 if (select (socketFileDescriptor + 1 , NULL , &set, NULL , &tv) < 0 ) {
404419 return 0 ;
405420 }
@@ -459,6 +474,18 @@ size_t WiFiClient::write(Stream &stream)
459474
460475int WiFiClient::read (uint8_t *buf, size_t size)
461476{
477+ if (_lastReadTimeout != _timeout){
478+ if (fd () >= 0 ){
479+ struct timeval tv;
480+ tv.tv_sec = _timeout/1000 ;
481+ tv.tv_usec = 0 ;
482+ if (setSocketOption (SO_RCVTIMEO, (char *)&tv, sizeof (struct timeval )) >= 0 )
483+ {
484+ _lastReadTimeout = _timeout;
485+ }
486+ }
487+ }
488+
462489 int res = -1 ;
463490 if (_rxBuffer) {
464491 res = _rxBuffer->read (buf, size);
0 commit comments