Skip to content
Browse files

* win32/win32.c (finish_overlapped_socket, overlapped_socket_io):

  replace ECONNABORTED to EPIPE in send, sendto and sendmsg to improve
  BSD socket compatibility.  this change removes a failure on the test
  of net/ftp.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent 510bbe0 commit 87c8c5edf43a7f7d33d5fe75f51ef410a03b93b1 @unak unak committed May 23, 2012
Showing with 28 additions and 8 deletions.
  1. +7 −0 ChangeLog
  2. +21 −8 win32/win32.c
View
7 ChangeLog
@@ -1,3 +1,10 @@
+Wed May 23 10:18:54 2012 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * win32/win32.c (finish_overlapped_socket, overlapped_socket_io):
+ replace ECONNABORTED to EPIPE in send, sendto and sendmsg to improve
+ BSD socket compatibility. this change removes a failure on the test
+ of net/ftp.
+
Wed May 23 05:35:58 2012 Eric Hodel <drbrain@segment7.net>
* lib/net/http.rb: Broke up Net::HTTP into individual files.
View
29 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;

0 comments on commit 87c8c5e

Please sign in to comment.
Something went wrong with that request. Please try again.