From a8bdd28d10c2c5981e944e945eed95f6c4ad44bc Mon Sep 17 00:00:00 2001 From: usa Date: Wed, 15 Jun 2011 18:04:13 +0000 Subject: * thread.c (do_select): Windows: no need to poll if select(2) is cancelable. * thread_win32.c (native_fd_select): new function to make select(2) cancelable. * thread_win32.c (rb_w32_check_interrupt): new function for checking interrupt. * win32/win32.c (rb_w32_select_with_thread): new function. cancelable select(2). * win32/win32.c (rb_w32_select): use above function internally. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- win32/win32.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'win32') diff --git a/win32/win32.c b/win32/win32.c index d636b74e2d..b3ffcffa07 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -2591,9 +2591,13 @@ compare(const struct timeval *t1, const struct timeval *t2) } #undef Sleep -int WSAAPI -rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, - struct timeval *timeout) + +int rb_w32_check_interrupt(void *); /* @internal */ + +/* @internal */ +int +rb_w32_select_with_thread(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, + struct timeval *timeout, void *th) { int r; rb_fdset_t pipe_rd; @@ -2672,6 +2676,10 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, wait.tv_sec = 0; wait.tv_usec = 10 * 1000; // 10ms zero.tv_sec = 0; zero.tv_usec = 0; // 0ms for (;;) { + if (th && rb_w32_check_interrupt(th) != WAIT_TIMEOUT) { + r = -1; + break; + } if (nonsock) { // modifying {else,pipe,cons}_rd is safe because // if they are modified, function returns immediately. @@ -2724,6 +2732,13 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, return r; } +int WSAAPI +rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, + struct timeval *timeout) +{ + return rb_w32_select_with_thread(nfds, rd, wr, ex, timeout, 0); +} + static FARPROC get_wsa_extension_function(SOCKET s, GUID *guid) { -- cgit v1.2.3