summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-04-11 20:55:22 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2023-05-13 16:42:04 +0100
commit14c820b191a7083bf9a54792e09afcd83e0f0206 (patch)
treea9adc137cd912a73a9fedbab8de5b1130efb5767
parent03eebab8a9fc353e96b2f6932d28defd5d868bca (diff)
downloadlibgit2-14c820b191a7083bf9a54792e09afcd83e0f0206.tar.gz
win32: use WSAGetLastError to determine blocking
-rw-r--r--src/libgit2/streams/socket.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/libgit2/streams/socket.c b/src/libgit2/streams/socket.c
index 3bfc3fd0f..a463312fd 100644
--- a/src/libgit2/streams/socket.c
+++ b/src/libgit2/streams/socket.c
@@ -114,6 +114,19 @@ static int handle_sockerr(GIT_SOCKET socket)
return -1;
}
+GIT_INLINE(bool) connect_would_block(int error)
+{
+#ifdef GIT_WIN32
+ if (error == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
+ return true;
+#endif
+
+ if (error == -1 && errno == EINPROGRESS)
+ return true;
+
+ return false;
+}
+
static int connect_with_timeout(
GIT_SOCKET socket,
const struct sockaddr *address,
@@ -128,7 +141,7 @@ static int connect_with_timeout(
error = connect(socket, address, address_len);
- if (error == 0 || (error == -1 && errno != EINPROGRESS))
+ if (error == 0 || !connect_would_block(error))
return error;
fd.fd = socket;