@@ -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
196206int 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+
379386int WiFiClientSecure::setSocketOption (int option, char * value, size_t len)
380387{
381388 int res = setsockopt (sslclient->socket , SOL_SOCKET, option, value, len);
0 commit comments