Skip to content

Commit 14c820b

Browse files
committed
win32: use WSAGetLastError to determine blocking
1 parent 03eebab commit 14c820b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/libgit2/streams/socket.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ static int handle_sockerr(GIT_SOCKET socket)
114114
return -1;
115115
}
116116

117+
GIT_INLINE(bool) connect_would_block(int error)
118+
{
119+
#ifdef GIT_WIN32
120+
if (error == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
121+
return true;
122+
#endif
123+
124+
if (error == -1 && errno == EINPROGRESS)
125+
return true;
126+
127+
return false;
128+
}
129+
117130
static int connect_with_timeout(
118131
GIT_SOCKET socket,
119132
const struct sockaddr *address,
@@ -128,7 +141,7 @@ static int connect_with_timeout(
128141

129142
error = connect(socket, address, address_len);
130143

131-
if (error == 0 || (error == -1 && errno != EINPROGRESS))
144+
if (error == 0 || !connect_would_block(error))
132145
return error;
133146

134147
fd.fd = socket;

0 commit comments

Comments
 (0)