* win32/win32.c (do_select, rb_w32_select): brush up.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9342 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2005-10-01 14:57:06 +00:00
parent 36941b8465
commit 1110e7123c
2 changed files with 74 additions and 47 deletions

View File

@ -1,3 +1,7 @@
Sat Oct 1 23:55:24 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (do_select, rb_w32_select): brush up.
Sat Oct 1 12:57:02 2005 Tanaka Akira <akr@m17n.org>
* bignum.c (rb_big_rand): removed. [ruby-dev:25405]

View File

@ -61,7 +61,7 @@
#endif
#if HAVE_WSAWAITFORMULTIPLEEVENTS
# define USE_INTERRUPT_WINSOCK
# define USE_INTERRUPT_WINSOCK 1
#endif
#if USE_INTERRUPT_WINSOCK
@ -2007,21 +2007,34 @@ is_readable_console(SOCKET sock) /* call this for console only */
return ret;
}
static void catch_interrupt(void);
static long
do_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
struct timeval *timeout)
{
long r = 0;
if (nfds == 0 && timeout) {
Sleep(timeout->tv_sec * 1000 + timeout->tv_usec / 1000);
if (nfds == 0) {
if (timeout)
rb_w32_sleep(timeout->tv_sec * 1000 + timeout->tv_usec / 1000);
else
rb_w32_sleep(INFINITE);
}
else {
#if !USE_INTERRUPT_WINSOCK
int trap_immediate = rb_trap_immediate;
#endif /* !USE_INTERRUPT_WINSOCK */
RUBY_CRITICAL(
r = select(nfds, rd, wr, ex, timeout);
if (r == SOCKET_ERROR) {
errno = map_errno(WSAGetLastError());
r = -1;
}
);
#if !USE_INTERRUPT_WINSOCK
rb_trap_immediate = trap_immediate;
catch_interrupt();
#endif /* !USE_INTERRUPT_WINSOCK */
}
return r;
@ -2051,8 +2064,9 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
fd_set cons_rd;
fd_set else_rd;
fd_set else_wr;
#ifdef USE_INTERRUPT_WINSOCK
#if USE_INTERRUPT_WINSOCK
fd_set trap;
int ret;
#endif /* USE_INTERRUPT_WINSOCK */
int nonsock = 0;
@ -2099,7 +2113,6 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
ex = &trap;
#endif /* USE_INTERRUPT_WINSOCK */
RUBY_CRITICAL(
if (nonsock) {
struct timeval rest;
struct timeval wait;
@ -2137,7 +2150,17 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
}
else
r = do_select(nfds, rd, wr, ex, timeout);
);
#if USE_INTERRUPT_WINSOCK
RUBY_CRITICAL(ret = __WSAFDIsSet((SOCKET)interrupted_event, ex));
if (ret) {
// In this case, we must restore all FDs. But this is only a test
// code, so we think about that later.
errno = EINTR;
r = -1;
}
#endif /* USE_INTERRUPT_WINSOCK */
return r;
}