diff options
author | Edward Thomson <ethomson@vercel.com> | 2023-03-21 09:34:09 +0000 |
---|---|---|
committer | Edward Thomson <ethomson@vercel.com> | 2023-03-21 09:36:37 +0000 |
commit | 4fe577247ab3dd5b9e74ffaaddf24027824b6a9d (patch) | |
tree | 917bea00bb89f37abe87b7ef4b351352b0705880 /src/libgit2/libgit2.c | |
parent | da0454e1440d72609df85fb77a7b3866d668e082 (diff) | |
download | libgit2-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 'src/libgit2/libgit2.c')
-rw-r--r-- | src/libgit2/libgit2.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/libgit2/libgit2.c b/src/libgit2/libgit2.c index 5d796b1f7..7244c48d9 100644 --- a/src/libgit2/libgit2.c +++ b/src/libgit2/libgit2.c @@ -47,6 +47,8 @@ extern size_t git_indexer__max_objects; extern bool git_disable_pack_keep_file_checks; extern int git_odb__packed_priority; extern int git_odb__loose_priority; +extern int git_socket_stream__connect_timeout; +extern int git_socket_stream__timeout; char *git__user_agent; char *git__ssl_ciphers; @@ -435,6 +437,38 @@ int git_libgit2_opts(int key, ...) error = git_sysdir_set(GIT_SYSDIR_HOME, va_arg(ap, const char *)); break; + case GIT_OPT_GET_SERVER_CONNECT_TIMEOUT: + *(va_arg(ap, int *)) = git_socket_stream__connect_timeout; + + case GIT_OPT_SET_SERVER_CONNECT_TIMEOUT: + { + int timeout = va_arg(ap, int); + + if (timeout < 0) { + git_error_set(GIT_ERROR_INVALID, "invalid connect timeout"); + error = -1; + } else { + git_socket_stream__connect_timeout = timeout; + } + } + break; + + case GIT_OPT_GET_SERVER_TIMEOUT: + *(va_arg(ap, int *)) = git_socket_stream__timeout; + + case GIT_OPT_SET_SERVER_TIMEOUT: + { + int timeout = va_arg(ap, int); + + if (timeout < 0) { + git_error_set(GIT_ERROR_INVALID, "invalid timeout"); + error = -1; + } else { + git_socket_stream__timeout = timeout; + } + } + break; + default: git_error_set(GIT_ERROR_INVALID, "invalid option key"); error = -1; |