summaryrefslogtreecommitdiff
path: root/sockcompat.c
diff options
context:
space:
mode:
authorKristján Valur Jónsson <sweskman@gmail.com>2021-03-26 14:40:32 +0000
committermichael-grunder <michael.grunder@gmail.com>2022-06-26 13:19:33 -0700
commit5e002bc21c6b7483592cd66417bf7a374590b973 (patch)
tree19e5aa2b10816bbf78e780f0b9cd52695ca2e92d /sockcompat.c
parent5d68ad2f48e908ff7fe2debe22f71182c2150547 (diff)
Support failed async connects on windows.
Diffstat (limited to 'sockcompat.c')
-rw-r--r--sockcompat.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/sockcompat.c b/sockcompat.c
index f99d14b..31df325 100644
--- a/sockcompat.c
+++ b/sockcompat.c
@@ -180,10 +180,17 @@ int win32_connect(SOCKET sockfd, const struct sockaddr *addr, socklen_t addrlen)
/* For Winsock connect(), the WSAEWOULDBLOCK error means the same thing as
* EINPROGRESS for POSIX connect(), so we do that translation to keep POSIX
- * logic consistent. */
- if (errno == EWOULDBLOCK) {
+ * logic consistent.
+ * Additionally, WSAALREADY is can be reported as WSAEINVAL to and this is
+ * translated to EIO. Convert appropriately
+ */
+ int err = errno;
+ if (err == EWOULDBLOCK) {
errno = EINPROGRESS;
}
+ else if (err == EIO) {
+ errno = EALREADY;
+ }
return ret != SOCKET_ERROR ? ret : -1;
}
@@ -205,6 +212,14 @@ int win32_getsockopt(SOCKET sockfd, int level, int optname, void *optval, sockle
} else {
ret = getsockopt(sockfd, level, optname, (char*)optval, optlen);
}
+ if (ret != SOCKET_ERROR && level == SOL_SOCKET && optname == SO_ERROR) {
+ /* translate SO_ERROR codes, if non-zero */
+ int err = *(int*)optval;
+ if (err != 0) {
+ err = _wsaErrorToErrno(err);
+ *(int*)optval = err;
+ }
+ }
_updateErrno(ret != SOCKET_ERROR);
return ret != SOCKET_ERROR ? ret : -1;
}