From f0bcbbef671e7ba3592cdb730bbc9d9f8f3cfc10 Mon Sep 17 00:00:00 2001 From: ocean Date: Sat, 17 Sep 2005 05:22:33 +0000 Subject: * win32/win32.c (rb_w32_select): I hope performance problem was solved. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9194 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- win32/win32.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'win32/win32.c') diff --git a/win32/win32.c b/win32/win32.c index 10fc5b3a04..3ca7380550 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -2025,6 +2025,21 @@ do_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, return r; } +static int +subst(struct timeval *rest, const struct timeval *wait) +{ + while (rest->tv_usec < wait->tv_usec) { + if (rest->tv_sec <= wait->tv_sec) { + return 0; + } + rest->tv_sec -= 1; + rest->tv_usec += 1000 * 1000; + } + rest->tv_sec -= wait->tv_sec; + rest->tv_usec -= wait->tv_usec; + return 1; +} + long rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *timeout) @@ -2083,8 +2098,11 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, RUBY_CRITICAL( if (pipe_rd.fd_count || cons_rd.fd_count) { - long sec = timeout ? timeout->tv_sec + 1 : 0/*dummy*/; - while (!timeout || sec--) { + struct timeval rest; + struct timeval wait; + if (timeout) rest = *timeout; + wait.tv_sec = 0; wait.tv_usec = 10 * 1000; // 10ms + do { fd_set buf; buf.fd_count = 0; // pipe extract_fd(&buf, &pipe_rd, is_readable_pipe); @@ -2092,21 +2110,19 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, extract_fd(&buf, &cons_rd, is_readable_console); // socket if (buf.fd_count) { - struct timeval val; val.tv_sec = 0; val.tv_usec = 0; - r = do_select(nfds, rd, wr, ex, &val); + r = do_select(nfds, rd, wr, ex, &wait); if (r >= 0) { r += buf.fd_count; extract_fd(rd, &buf, NULL); // move all `buf' contents into `rd'. } - // XXX: should I ignore socket error and returns only readable pipe? + // XXX: should I ignore socket error and returns readable pipe/console? break; } else { - struct timeval val; val.tv_sec = 1; val.tv_usec = 0; - r = do_select(nfds, rd, wr, ex, &val); + r = do_select(nfds, rd, wr, ex, &wait); if (r) break; // readable or error (not pending) } - } + } while (!timeout || subst(&rest, &wait)); } else r = do_select(nfds, rd, wr, ex, timeout); -- cgit v1.2.3