File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
libraries/ESP8266HTTPClient/src Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ HTTPClient::HTTPClient() {
5050 _returnCode = 0 ;
5151 _size = -1 ;
5252 _canReuse = false ;
53+ _tcpTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT;
5354
5455}
5556
@@ -252,6 +253,17 @@ void HTTPClient::setAuthorization(const char * auth) {
252253 }
253254}
254255
256+ /* *
257+ * set the timeout for the TCP connection
258+ * @param timeout unsigned int
259+ */
260+ void HTTPClient::setTimeout (uint16_t timeout) {
261+ _tcpTimeout = timeout;
262+ if (connected ()) {
263+ _tcp->setTimeout (timeout);
264+ }
265+ }
266+
255267/* *
256268 * send a GET request
257269 * @return http code
@@ -673,7 +685,7 @@ bool HTTPClient::connect(void) {
673685 }
674686
675687 // set Timeout for readBytesUntil and readStringUntil
676- _tcp->setTimeout (HTTPCLIENT_TCP_TIMEOUT );
688+ _tcp->setTimeout (_tcpTimeout );
677689
678690#ifdef ESP8266
679691 _tcp->setNoDelay (true );
Original file line number Diff line number Diff line change 3131#define DEBUG_HTTPCLIENT (...)
3232#endif
3333
34- #define HTTPCLIENT_TCP_TIMEOUT (1000 )
34+ #define HTTPCLIENT_DEFAULT_TCP_TIMEOUT (1000 )
3535
3636// / HTTP client errors
3737#define HTTPC_ERROR_CONNECTION_REFUSED (-1 )
@@ -127,6 +127,7 @@ class HTTPClient {
127127 void setUserAgent (const char * userAgent);
128128 void setAuthorization (const char * user, const char * password);
129129 void setAuthorization (const char * auth);
130+ void setTimeout (uint16_t timeout);
130131
131132 // / request handling
132133 int GET ();
@@ -170,7 +171,7 @@ class HTTPClient {
170171 String _host;
171172 uint16_t _port;
172173 bool _reuse;
173-
174+ uint16_t _tcpTimeout;
174175
175176 String _url;
176177 bool _https;
You can’t perform that action at this time.
0 commit comments