Skip to content

Commit fb1668e

Browse files
committed
WiFiClients - setTimeout replaced with setConnectionTimeout
to not shadow Stream::setTimeout which has a different purpose
1 parent e382b6a commit fb1668e

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed

Diff for: libraries/HTTPClient/src/HTTPClient.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ void HTTPClient::setTimeout(uint16_t timeout)
495495
{
496496
_tcpTimeout = timeout;
497497
if(connected()) {
498-
_client->setTimeout((timeout + 500) / 1000);
498+
_client->setConnectionTimeout(timeout + 500);
499499
}
500500
}
501501

@@ -1165,7 +1165,8 @@ bool HTTPClient::connect(void)
11651165
}
11661166

11671167
// set Timeout for WiFiClient and for Stream::readBytesUntil() and Stream::readStringUntil()
1168-
_client->setTimeout((_tcpTimeout + 500) / 1000);
1168+
_client->setConnectionTimeout(_tcpTimeout + 500);
1169+
_client->setTimeout(_tcpTimeout + 500);
11691170

11701171
log_d(" connected to %s:%u", _host.c_str(), _port);
11711172

Diff for: libraries/HTTPUpdate/examples/httpUpdateSecure/httpUpdateSecure.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void loop() {
9696
client.setCACert(rootCACertificate);
9797

9898
// Reading data over SSL may be slow, use an adequate timeout
99-
client.setTimeout(12000 / 1000); // timeout argument is defined in seconds for setTimeout
99+
client.setTimeout(12000);
100100

101101
// The line below is optional. It can be used to blink the LED on the board during flashing
102102
// The LED will be on during download of one buffer of data from the network. The LED will

Diff for: libraries/WebServer/src/WebServer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ void WebServer::handleClient() {
302302
if (_parseRequest(_currentClient)) {
303303
// because HTTP_MAX_SEND_WAIT is expressed in milliseconds,
304304
// it must be divided by 1000
305-
_currentClient.setTimeout(HTTP_MAX_SEND_WAIT / 1000);
305+
_currentClient.setTimeout(HTTP_MAX_SEND_WAIT);
306306
_contentLength = CONTENT_LENGTH_NOT_SET;
307307
_handleRequest();
308308

Diff for: libraries/WiFi/src/WiFiClient.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,13 @@ int WiFiClient::setSocketOption(int level, int option, const void* value, size_t
322322
return res;
323323
}
324324

325-
int WiFiClient::setTimeout(uint32_t seconds)
325+
int WiFiClient::setConnectionTimeout(uint32_t milliseconds)
326326
{
327-
Client::setTimeout(seconds * 1000); // This should be here?
328-
_timeout = seconds * 1000;
327+
_timeout = milliseconds;
329328
if(fd() >= 0) {
330329
struct timeval tv;
331-
tv.tv_sec = seconds;
332-
tv.tv_usec = 0;
330+
tv.tv_sec = _timeout / 1000;
331+
tv.tv_usec = (_timeout % 1000) * 1000;
333332
if(setSocketOption(SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0) {
334333
return -1;
335334
}

Diff for: libraries/WiFi/src/WiFiClient.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ESPLwIPClient : public Client
3333
public:
3434
virtual int connect(IPAddress ip, uint16_t port, int32_t timeout) = 0;
3535
virtual int connect(const char *host, uint16_t port, int32_t timeout) = 0;
36-
virtual int setTimeout(uint32_t seconds) = 0;
36+
virtual int setConnectionTimeout(uint32_t milliseconds) = 0;
3737
};
3838

3939
class WiFiClient : public ESPLwIPClient
@@ -42,7 +42,7 @@ class WiFiClient : public ESPLwIPClient
4242
std::shared_ptr<WiFiClientSocketHandle> clientSocketHandle;
4343
std::shared_ptr<WiFiClientRxBuffer> _rxBuffer;
4444
bool _connected;
45-
int _timeout;
45+
uint32_t _timeout;
4646

4747
public:
4848
WiFiClient *next;
@@ -90,7 +90,7 @@ class WiFiClient : public ESPLwIPClient
9090
int setSocketOption(int level, int option, const void* value, size_t len);
9191
int setOption(int option, int *value);
9292
int getOption(int option, int *value);
93-
int setTimeout(uint32_t seconds);
93+
int setConnectionTimeout(uint32_t milliseconds);
9494
int setNoDelay(bool nodelay);
9595
bool getNoDelay();
9696

Diff for: libraries/WiFiClientSecure/src/WiFiClientSecure.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,13 @@ void WiFiClientSecure::setAlpnProtocols(const char **alpn_protos)
375375
{
376376
_alpn_protos = alpn_protos;
377377
}
378-
int WiFiClientSecure::setTimeout(uint32_t seconds)
378+
int WiFiClientSecure::setConnectionTimeout(uint32_t milliseconds)
379379
{
380-
_timeout = seconds * 1000;
380+
_timeout = milliseconds;
381381
if (sslclient->socket >= 0) {
382382
struct timeval tv;
383-
tv.tv_sec = seconds;
384-
tv.tv_usec = 0;
383+
tv.tv_sec = _timeout / 1000;
384+
tv.tv_usec = (_timeout % 1000) * 1000;
385385
if(setSocketOption(SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0) {
386386
return -1;
387387
}

Diff for: libraries/WiFiClientSecure/src/WiFiClientSecure.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class WiFiClientSecure : public WiFiClient
8080
void setAlpnProtocols(const char **alpn_protos);
8181
const mbedtls_x509_crt* getPeerCertificate() { return mbedtls_ssl_get_peer_cert(&sslclient->ssl_ctx); };
8282
bool getFingerprintSHA256(uint8_t sha256_result[32]) { return get_peer_fingerprint(sslclient, sha256_result); };
83-
int setTimeout(uint32_t seconds);
83+
int setConnectionTimeout(uint32_t milliseconds);
8484
int fd() const;
8585

8686
operator bool()

0 commit comments

Comments
 (0)