Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e18f08e

Browse filesBrowse files
rtpmsysSuGlider
andauthored
Fix error in WiFiClient.cpp where the connect function fails for timeouts below 1 second (espressif#7686)
* Update WiFiClient.cpp This change will allow specifying connect timeouts below 1 second. Without this change, if connect timeouts under 1 second are given, the connect defaults to 0ms and fails. This will also allow timeouts in fractions of seconds, e.g. 1500ms. Without this change, connect timeouts are truncated to full second increments. * Make parameter timeout_ms clear * Change connection timeout_ms name for clarity --------- Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com>
1 parent ba53183 commit e18f08e
Copy full SHA for e18f08e

File tree

Expand file treeCollapse file tree

2 files changed

+7
-7
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+7
-7
lines changed

‎libraries/WiFi/src/WiFiClient.cpp

Copy file name to clipboardExpand all lines: libraries/WiFi/src/WiFiClient.cpp
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ int WiFiClient::connect(IPAddress ip, uint16_t port)
210210
{
211211
return connect(ip,port,_timeout);
212212
}
213-
int WiFiClient::connect(IPAddress ip, uint16_t port, int32_t timeout)
213+
int WiFiClient::connect(IPAddress ip, uint16_t port, int32_t timeout_ms)
214214
{
215-
_timeout = timeout;
215+
_timeout = timeout_ms;
216216
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
217217
if (sockfd < 0) {
218218
log_e("socket: %d", errno);
@@ -231,7 +231,7 @@ int WiFiClient::connect(IPAddress ip, uint16_t port, int32_t timeout)
231231
FD_ZERO(&fdset);
232232
FD_SET(sockfd, &fdset);
233233
tv.tv_sec = _timeout / 1000;
234-
tv.tv_usec = 0;
234+
tv.tv_usec = (_timeout % 1000) * 1000;
235235

236236
#ifdef ESP_IDF_VERSION_MAJOR
237237
int res = lwip_connect(sockfd, (struct sockaddr*)&serveraddr, sizeof(serveraddr));
@@ -292,13 +292,13 @@ int WiFiClient::connect(const char *host, uint16_t port)
292292
return connect(host,port,_timeout);
293293
}
294294

295-
int WiFiClient::connect(const char *host, uint16_t port, int32_t timeout)
295+
int WiFiClient::connect(const char *host, uint16_t port, int32_t timeout_ms)
296296
{
297297
IPAddress srv((uint32_t)0);
298298
if(!WiFiGenericClass::hostByName(host, srv)){
299299
return 0;
300300
}
301-
return connect(srv, port, timeout);
301+
return connect(srv, port, timeout_ms);
302302
}
303303

304304
int WiFiClient::setSocketOption(int option, char* value, size_t len)

‎libraries/WiFi/src/WiFiClient.h

Copy file name to clipboardExpand all lines: libraries/WiFi/src/WiFiClient.h
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ class WiFiClient : public ESPLwIPClient
5050
WiFiClient(int fd);
5151
~WiFiClient();
5252
int connect(IPAddress ip, uint16_t port);
53-
int connect(IPAddress ip, uint16_t port, int32_t timeout);
53+
int connect(IPAddress ip, uint16_t port, int32_t timeout_ms);
5454
int connect(const char *host, uint16_t port);
55-
int connect(const char *host, uint16_t port, int32_t timeout);
55+
int connect(const char *host, uint16_t port, int32_t timeout_ms);
5656
size_t write(uint8_t data);
5757
size_t write(const uint8_t *buf, size_t size);
5858
size_t write_P(PGM_P buf, size_t size);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.