summaryrefslogtreecommitdiff
path: root/win32/win32.c
diff options
context:
space:
mode:
Diffstat (limited to 'win32/win32.c')
-rw-r--r--win32/win32.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 16ec249b4c5..34c62fb1a03 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -3084,7 +3084,7 @@ rb_w32_listen(int s, int backlog)
/* License: Ruby's */
static int
-finish_overlapped_socket(SOCKET s, WSAOVERLAPPED *wol, int result, DWORD *len, DWORD size)
+finish_overlapped_socket(BOOL input, SOCKET s, WSAOVERLAPPED *wol, int result, DWORD *len, DWORD size)
{
DWORD flg;
int err;
@@ -3103,7 +3103,10 @@ finish_overlapped_socket(SOCKET s, WSAOVERLAPPED *wol, int result, DWORD *len, D
}
/* thru */
default:
- errno = map_errno(WSAGetLastError());
+ if ((err = WSAGetLastError()) == WSAECONNABORTED && !input)
+ errno = EPIPE;
+ else
+ errno = map_errno(WSAGetLastError());
/* thru */
case WAIT_OBJECT_0 + 1:
/* interrupted */
@@ -3113,7 +3116,10 @@ finish_overlapped_socket(SOCKET s, WSAOVERLAPPED *wol, int result, DWORD *len, D
}
}
else {
- errno = map_errno(err);
+ if (err == WSAECONNABORTED && !input)
+ errno = EPIPE;
+ else
+ errno = map_errno(err);
*len = -1;
}
CloseHandle(wol->hEvent);
@@ -3146,15 +3152,22 @@ overlapped_socket_io(BOOL input, int fd, char *buf, int len, int flags,
r = recvfrom(s, buf, len, flags, addr, addrlen);
else
r = recv(s, buf, len, flags);
+ if (r == SOCKET_ERROR)
+ errno = map_errno(WSAGetLastError());
}
else {
if (addr && addrlen)
r = sendto(s, buf, len, flags, addr, *addrlen);
else
r = send(s, buf, len, flags);
+ if (r == SOCKET_ERROR) {
+ DWORD err = WSAGetLastError();
+ if (err == WSAECONNABORTED)
+ errno = EPIPE;
+ else
+ errno = map_errno(err);
+ }
}
- if (r == SOCKET_ERROR)
- errno = map_errno(WSAGetLastError());
});
}
else {
@@ -3182,7 +3195,7 @@ overlapped_socket_io(BOOL input, int fd, char *buf, int len, int flags,
}
});
- finish_overlapped_socket(s, &wol, ret, &rlen, size);
+ finish_overlapped_socket(input, s, &wol, ret, &rlen, size);
r = (int)rlen;
}
@@ -3300,7 +3313,7 @@ recvmsg(int fd, struct msghdr *msg, int flags)
ret = pWSARecvMsg(s, &wsamsg, &size, &wol, NULL);
});
- ret = finish_overlapped_socket(s, &wol, ret, &len, size);
+ ret = finish_overlapped_socket(TRUE, s, &wol, ret, &len, size);
}
if (ret == SOCKET_ERROR)
return -1;
@@ -3357,7 +3370,7 @@ sendmsg(int fd, const struct msghdr *msg, int flags)
ret = pWSASendMsg(s, &wsamsg, flags, &size, &wol, NULL);
});
- finish_overlapped_socket(s, &wol, ret, &len, size);
+ finish_overlapped_socket(FALSE, s, &wol, ret, &len, size);
}
return len;