mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* win32/win32.c (finish_overlapped_socket): refactoring.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
877e90f17a
commit
7dd7ce0ff7
2 changed files with 47 additions and 94 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Mon Nov 8 11:47:39 2010 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
|
* win32/win32.c (finish_overlapped_socket): refactoring.
|
||||||
|
|
||||||
Mon Nov 8 11:02:21 2010 NAKAMURA Usaku <usa@ruby-lang.org>
|
Mon Nov 8 11:02:21 2010 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* win32/win32.c (get_proc_address): refactoring.
|
* win32/win32.c (get_proc_address): refactoring.
|
||||||
|
|
137
win32/win32.c
137
win32/win32.c
|
@ -2858,6 +2858,44 @@ rb_w32_listen(int s, int backlog)
|
||||||
#undef send
|
#undef send
|
||||||
#undef sendto
|
#undef sendto
|
||||||
|
|
||||||
|
static int
|
||||||
|
finish_overlapped_socket(SOCKET s, WSAOVERLAPPED *wol, int result, DWORD *len, DWORD size)
|
||||||
|
{
|
||||||
|
DWORD flg;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
if (result != SOCKET_ERROR)
|
||||||
|
*len = size;
|
||||||
|
else if ((err = WSAGetLastError()) == WSA_IO_PENDING) {
|
||||||
|
switch (rb_w32_wait_events_blocking(&wol->hEvent, 1, INFINITE)) {
|
||||||
|
case WAIT_OBJECT_0:
|
||||||
|
RUBY_CRITICAL(
|
||||||
|
result = WSAGetOverlappedResult(s, wol, &size, TRUE, &flg)
|
||||||
|
);
|
||||||
|
if (result) {
|
||||||
|
*len = size;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* thru */
|
||||||
|
default:
|
||||||
|
errno = map_errno(WSAGetLastError());
|
||||||
|
/* thru */
|
||||||
|
case WAIT_OBJECT_0 + 1:
|
||||||
|
/* interrupted */
|
||||||
|
*len = -1;
|
||||||
|
cancel_io((HANDLE)s);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
errno = map_errno(err);
|
||||||
|
*len = -1;
|
||||||
|
}
|
||||||
|
CloseHandle(wol->hEvent);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
overlapped_socket_io(BOOL input, int fd, char *buf, int len, int flags,
|
overlapped_socket_io(BOOL input, int fd, char *buf, int len, int flags,
|
||||||
struct sockaddr *addr, int *addrlen)
|
struct sockaddr *addr, int *addrlen)
|
||||||
|
@ -2869,7 +2907,6 @@ overlapped_socket_io(BOOL input, int fd, char *buf, int len, int flags,
|
||||||
DWORD flg;
|
DWORD flg;
|
||||||
WSAOVERLAPPED wol;
|
WSAOVERLAPPED wol;
|
||||||
WSABUF wbuf;
|
WSABUF wbuf;
|
||||||
int err;
|
|
||||||
SOCKET s;
|
SOCKET s;
|
||||||
|
|
||||||
if (!NtSocketsInitialized)
|
if (!NtSocketsInitialized)
|
||||||
|
@ -2920,35 +2957,7 @@ overlapped_socket_io(BOOL input, int fd, char *buf, int len, int flags,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (ret != SOCKET_ERROR) {
|
finish_overlapped_socket(s, &wol, ret, &r, size);
|
||||||
r = size;
|
|
||||||
}
|
|
||||||
else if ((err = WSAGetLastError()) == WSA_IO_PENDING) {
|
|
||||||
switch (rb_w32_wait_events_blocking(&wol.hEvent, 1, INFINITE)) {
|
|
||||||
case WAIT_OBJECT_0:
|
|
||||||
RUBY_CRITICAL(
|
|
||||||
ret = WSAGetOverlappedResult(s, &wol, &size, TRUE, &flg)
|
|
||||||
);
|
|
||||||
if (ret) {
|
|
||||||
r = size;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* thru */
|
|
||||||
default:
|
|
||||||
errno = map_errno(WSAGetLastError());
|
|
||||||
/* thru */
|
|
||||||
case WAIT_OBJECT_0 + 1:
|
|
||||||
/* interrupted */
|
|
||||||
r = -1;
|
|
||||||
cancel_io((HANDLE)s);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
errno = map_errno(err);
|
|
||||||
r = -1;
|
|
||||||
}
|
|
||||||
CloseHandle(wol.hEvent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
@ -3053,44 +3062,14 @@ recvmsg(int fd, struct msghdr *msg, int flags)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DWORD size;
|
DWORD size;
|
||||||
int err;
|
|
||||||
WSAOVERLAPPED wol;
|
WSAOVERLAPPED wol;
|
||||||
memset(&wol, 0, sizeof(wol));
|
memset(&wol, 0, sizeof(wol));
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
wol.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
wol.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||||
ret = pWSARecvMsg(s, &wsamsg, &len, &wol, NULL);
|
ret = pWSARecvMsg(s, &wsamsg, &size, &wol, NULL);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (ret != SOCKET_ERROR) {
|
ret = finish_overlapped_socket(s, &wol, ret, &len, size);
|
||||||
/* nothing to do */
|
|
||||||
}
|
|
||||||
else if ((err = WSAGetLastError()) == WSA_IO_PENDING) {
|
|
||||||
DWORD flg;
|
|
||||||
switch (rb_w32_wait_events_blocking(&wol.hEvent, 1, INFINITE)) {
|
|
||||||
case WAIT_OBJECT_0:
|
|
||||||
RUBY_CRITICAL(
|
|
||||||
ret = WSAGetOverlappedResult(s, &wol, &size, TRUE, &flg)
|
|
||||||
);
|
|
||||||
if (ret) {
|
|
||||||
len = size;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* thru */
|
|
||||||
default:
|
|
||||||
errno = map_errno(WSAGetLastError());
|
|
||||||
/* thru */
|
|
||||||
case WAIT_OBJECT_0 + 1:
|
|
||||||
/* interrupted */
|
|
||||||
len = -1;
|
|
||||||
cancel_io((HANDLE)s);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
errno = map_errno(err);
|
|
||||||
len = -1;
|
|
||||||
}
|
|
||||||
CloseHandle(wol.hEvent);
|
|
||||||
}
|
}
|
||||||
if (ret == SOCKET_ERROR)
|
if (ret == SOCKET_ERROR)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -3141,44 +3120,14 @@ sendmsg(int fd, const struct msghdr *msg, int flags)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DWORD size;
|
DWORD size;
|
||||||
int err;
|
|
||||||
WSAOVERLAPPED wol;
|
WSAOVERLAPPED wol;
|
||||||
memset(&wol, 0, sizeof(wol));
|
memset(&wol, 0, sizeof(wol));
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
wol.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
wol.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||||
ret = pWSASendMsg(s, &wsamsg, flags, &len, &wol, NULL);
|
ret = pWSASendMsg(s, &wsamsg, flags, &size, &wol, NULL);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (ret != SOCKET_ERROR) {
|
finish_overlapped_socket(s, &wol, ret, &len, size);
|
||||||
/* nothing to do */
|
|
||||||
}
|
|
||||||
else if ((err = WSAGetLastError()) == WSA_IO_PENDING) {
|
|
||||||
DWORD flg;
|
|
||||||
switch (rb_w32_wait_events_blocking(&wol.hEvent, 1, INFINITE)) {
|
|
||||||
case WAIT_OBJECT_0:
|
|
||||||
RUBY_CRITICAL(
|
|
||||||
ret = WSAGetOverlappedResult(s, &wol, &size, TRUE, &flg)
|
|
||||||
);
|
|
||||||
if (ret) {
|
|
||||||
len = size;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* thru */
|
|
||||||
default:
|
|
||||||
errno = map_errno(WSAGetLastError());
|
|
||||||
/* thru */
|
|
||||||
case WAIT_OBJECT_0 + 1:
|
|
||||||
/* interrupted */
|
|
||||||
len = -1;
|
|
||||||
cancel_io((HANDLE)s);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
errno = map_errno(err);
|
|
||||||
len = -1;
|
|
||||||
}
|
|
||||||
CloseHandle(wol.hEvent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
|
|
Loading…
Reference in a new issue