summaryrefslogtreecommitdiff
path: root/include/git2/sys/stream.h
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@vercel.com>2023-03-21 09:34:09 +0000
committerEdward Thomson <ethomson@vercel.com>2023-03-21 09:36:37 +0000
commit4fe577247ab3dd5b9e74ffaaddf24027824b6a9d (patch)
tree917bea00bb89f37abe87b7ef4b351352b0705880 /include/git2/sys/stream.h
parentda0454e1440d72609df85fb77a7b3866d668e082 (diff)
downloadlibgit2-ethomson/nonblocking.tar.gz
streams: sockets are non-blocking and can timeoutethomson/nonblocking
Make socket I/O non-blocking and add optional timeouts. Users may now set `GIT_OPT_SET_SERVER_CONNECT_TIMEOUT` to set a shorter connection timeout. (The connect timeout cannot be longer than the operating system default.) Users may also now configure the socket read and write timeouts with `GIT_OPT_SET_SERVER_TIMEOUT`. By default, connects still timeout based on the operating system defaults (typically 75 seconds) and socket read and writes block. Add a test against our custom testing git server that ensures that we can timeout reads against a slow server.
Diffstat (limited to 'include/git2/sys/stream.h')
-rw-r--r--include/git2/sys/stream.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/include/git2/sys/stream.h b/include/git2/sys/stream.h
index e0e03a2d7..3d28d09b3 100644
--- a/include/git2/sys/stream.h
+++ b/include/git2/sys/stream.h
@@ -29,8 +29,22 @@ GIT_BEGIN_DECL
typedef struct git_stream {
int version;
- int encrypted;
- int proxy_support;
+ int encrypted : 1,
+ proxy_support : 1;
+
+ /**
+ * Timeout for read and write operations; can be set to `0` to
+ * block indefinitely.
+ */
+ int timeout;
+
+ /**
+ * Timeout to connect to the remote server; can be set to `0`
+ * to use the system defaults. This can be shorter than the
+ * system default - often 75 seconds - but cannot be longer.
+ */
+ int connect_timeout;
+
int GIT_CALLBACK(connect)(struct git_stream *);
int GIT_CALLBACK(certificate)(git_cert **, struct git_stream *);
int GIT_CALLBACK(set_proxy)(struct git_stream *, const git_proxy_options *proxy_opts);