From 4a965795f857b24e1ab0800f6dbe9af8a5fa425d Mon Sep 17 00:00:00 2001 From: shyouhei Date: Wed, 18 Nov 2009 05:13:34 +0000 Subject: merge revision(s) 24993:24997,25069:25074: * win32/win32.c (rb_w32_select): wait specified time on select. * win32/win32.c (rb_w32_select): on 1.8, we don't need to poll sockets, because our select is never called from multiple threads. * instruby.rb: win32/win32.h exists in srcdir. reported by arton ( http://www.artonx.org/diary/20090919.html#p01 ) * win32/win32.c (subtract): if the parameters are same value, should return zero. * win32/win32.c (rb_w32_select): of course, need to initialize rest. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@25838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- win32/win32.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'win32') diff --git a/win32/win32.c b/win32/win32.c index b5cd90dbb7..c9081327f5 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -2211,7 +2211,7 @@ subtract(struct timeval *rest, const struct timeval *wait) if (rest->tv_sec < wait->tv_sec) { return 0; } - while (rest->tv_usec < wait->tv_usec) { + while (rest->tv_usec <= wait->tv_usec) { if (rest->tv_sec <= wait->tv_sec) { return 0; } @@ -2305,6 +2305,7 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval zero; wait.tv_sec = 0; wait.tv_usec = 10 * 1000; // 10ms zero.tv_sec = 0; zero.tv_usec = 0; // 0ms + if (timeout) rest = *timeout; for (;;) { if (nonsock) { // modifying {else,pipe,cons}_rd is safe because @@ -2321,15 +2322,16 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, break; } else { - struct timeval *dowait = &wait; - fd_set orig_rd; fd_set orig_wr; fd_set orig_ex; + struct timeval *dowait = &wait; + if (timeout && compare(&rest, &wait) < 0) dowait = &rest; + if (rd) orig_rd = *rd; if (wr) orig_wr = *wr; if (ex) orig_ex = *ex; - r = do_select(nfds, rd, wr, ex, &zero); // polling + r = do_select(nfds, rd, wr, ex, dowait); if (r != 0) break; // signaled or error if (rd) *rd = orig_rd; if (wr) *wr = orig_wr; @@ -2340,9 +2342,7 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, gettimeofday(&now, NULL); rest = limit; if (!subtract(&rest, &now)) break; - if (compare(&rest, &wait) < 0) dowait = &rest; } - Sleep(dowait->tv_sec * 1000 + dowait->tv_usec / 1000); } } } -- cgit v1.2.3