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 f2cfe78

Browse filesBrowse files
authored
Fix HTTP Client failing to connect because of wrong timeout (espressif#6633)
1 parent 45583af commit f2cfe78
Copy full SHA for f2cfe78

File tree

Expand file treeCollapse file tree

2 files changed

+9
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-8
lines changed

‎libraries/HTTPClient/src/HTTPClient.h

Copy file name to clipboardExpand all lines: libraries/HTTPClient/src/HTTPClient.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class HTTPClient
276276
/// request handling
277277
String _host;
278278
uint16_t _port = 0;
279-
int32_t _connectTimeout = -1;
279+
int32_t _connectTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT;
280280
bool _reuse = true;
281281
uint16_t _tcpTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT;
282282
bool _useHTTP10 = false;

‎libraries/WiFi/src/WiFiClient.cpp

Copy file name to clipboardExpand all lines: libraries/WiFi/src/WiFiClient.cpp
+8-7Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ int WiFiClient::connect(IPAddress ip, uint16_t port, int32_t timeout)
230230
struct timeval tv;
231231
FD_ZERO(&fdset);
232232
FD_SET(sockfd, &fdset);
233-
tv.tv_sec = 0;
234-
tv.tv_usec = _timeout * 1000;
233+
tv.tv_sec = _timeout / 1000;
234+
tv.tv_usec = 0;
235235

236236
#ifdef ESP_IDF_VERSION_MAJOR
237237
int res = lwip_connect(sockfd, (struct sockaddr*)&serveraddr, sizeof(serveraddr));
@@ -271,17 +271,18 @@ int WiFiClient::connect(IPAddress ip, uint16_t port, int32_t timeout)
271271
}
272272
}
273273

274-
#define ROE_WIFICLIENT(x,msg) { if (((x)<0)) { log_e("LWIP Socket config of " msg " failed."); return -1; }}
275-
ROE_WIFICLIENT(lwip_setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)),"SO_RCVTIMEO");
276-
ROE_WIFICLIENT(lwip_setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)),"SO_SNDTIMEO");
274+
#define ROE_WIFICLIENT(x,msg) { if (((x)<0)) { log_e("Setsockopt '" msg "'' on fd %d failed. errno: %d, \"%s\"", sockfd, errno, strerror(errno)); return 0; }}
275+
ROE_WIFICLIENT(setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)),"SO_SNDTIMEO");
276+
ROE_WIFICLIENT(setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)),"SO_RCVTIMEO");
277277

278278
// These are also set in WiFiClientSecure, should be set here too?
279-
//ROE_WIFICLIENT(lwip_setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(enable)),"TCP_NODELAY");
280-
//ROE_WIFICLIENT (lwip_setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable)),"SO_KEEPALIVE");
279+
//ROE_WIFICLIENT(setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(enable)),"TCP_NODELAY");
280+
//ROE_WIFICLIENT (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable)),"SO_KEEPALIVE");
281281

282282
fcntl( sockfd, F_SETFL, fcntl( sockfd, F_GETFL, 0 ) & (~O_NONBLOCK) );
283283
clientSocketHandle.reset(new WiFiClientSocketHandle(sockfd));
284284
_rxBuffer.reset(new WiFiClientRxBuffer(sockfd));
285+
285286
_connected = true;
286287
return 1;
287288
}

0 commit comments

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