@@ -331,23 +331,25 @@ int WiFiClient::getSocketOption(int level, int option, const void* value, size_t
331331 return res;
332332}
333333
334-
335- int WiFiClient::setTimeout (uint32_t seconds)
334+ void WiFiClient::setTimeout (uint32_t seconds)
336335{
336+ _lastReadTimeout = Client::getTimeout ();
337+ _lastWriteTimeout = _lastReadTimeout;
337338 Client::setTimeout (seconds * 1000 ); // This should be here?
338339 _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+ // }
351353}
352354
353355int WiFiClient::setOption (int option, int *value)
@@ -418,6 +420,18 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size)
418420 tv.tv_usec = WIFI_CLIENT_SELECT_TIMEOUT_US;
419421 retry--;
420422
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+
421435 if (select (socketFileDescriptor + 1 , NULL , &set, NULL , &tv) < 0 ) {
422436 return 0 ;
423437 }
@@ -477,6 +491,18 @@ size_t WiFiClient::write(Stream &stream)
477491
478492int WiFiClient::read (uint8_t *buf, size_t size)
479493{
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+
480506 int res = -1 ;
481507 if (_rxBuffer) {
482508 res = _rxBuffer->read (buf, size);
0 commit comments