summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti <vicent@github.com>2014-08-27 19:18:46 +0200
committerVicent Marti <vicent@github.com>2014-08-27 19:18:46 +0200
commit893cfe06493533581d25c2f120334fbf4961cdff (patch)
treec3f0e9122fa9dcda17d4e936b695707a08b1266a
parent1485c6833a6142d03ac79ff976055797d68151b8 (diff)
parent86d0a53cd64efd3c7045790ac308d187e5acc625 (diff)
downloadlibgit2-893cfe06493533581d25c2f120334fbf4961cdff.tar.gz
Merge pull request #2502 from rnowosielski/remote_set_timeout
Set timeout on remote (Add timeout for WinHttpReceiveResponse #2147)
-rw-r--r--src/transports/winhttp.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index 1e46dfaee..6efc01706 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -35,7 +35,8 @@
#define WINHTTP_OPTION_PEERDIST_EXTENSION_STATE 109
#define CACHED_POST_BODY_BUF_SIZE 4096
#define UUID_LENGTH_CCH 32
-
+#define TIMEOUT_INFINITE -1
+#define DEFAULT_CONNECT_TIMEOUT 60000
#ifndef WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH
#define WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH 0
#endif
@@ -212,6 +213,8 @@ static int winhttp_stream_connect(winhttp_stream *s)
BOOL peerdist = FALSE;
int error = -1;
unsigned long disable_redirects = WINHTTP_DISABLE_REDIRECTS;
+ int default_timeout = TIMEOUT_INFINITE;
+ int default_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
/* Prepare URL */
git_buf_printf(&buf, "%s%s", t->connection_data.path, s->service_url);
@@ -240,6 +243,11 @@ static int winhttp_stream_connect(winhttp_stream *s)
goto on_error;
}
+ if (!WinHttpSetTimeouts(s->request, default_timeout, default_connect_timeout, default_timeout, default_timeout)) {
+ giterr_set(GITERR_OS, "Failed to set timeouts for WinHTTP");
+ goto on_error;
+ }
+
/* Set proxy if necessary */
if (git_remote__get_http_proxy(t->owner->owner, !!t->connection_data.use_ssl, &proxy_url) < 0)
goto on_error;
@@ -467,6 +475,8 @@ static int winhttp_connect(
int32_t port;
const char *default_port = "80";
int error = -1;
+ int default_timeout = TIMEOUT_INFINITE;
+ int default_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
/* Prepare port */
if (git__strtol32(&port, t->connection_data.port, NULL, 10) < 0)
@@ -491,6 +501,12 @@ static int winhttp_connect(
goto on_error;
}
+ if (!WinHttpSetTimeouts(t->session, default_timeout, default_connect_timeout, default_timeout, default_timeout)) {
+ giterr_set(GITERR_OS, "Failed to set timeouts for WinHTTP");
+ goto on_error;
+ }
+
+
/* Establish connection */
t->connection = WinHttpConnect(
t->session,