diff options
author | ocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-09-17 04:53:26 +0000 |
---|---|---|
committer | ocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-09-17 04:53:26 +0000 |
commit | aa21055faf3e8e02038fee143ba322e1ed3b26f1 (patch) | |
tree | 63a61af7285c97da2e554d0617ad009de7cd4115 /win32 | |
parent | 846b1c35e5c6d0ab787b9415ea586ccc843df562 (diff) | |
download | ruby-aa21055faf3e8e02038fee143ba322e1ed3b26f1.tar.gz |
* win32/win32.c (rb_w32_select): console support is back.
but still has performance problem because I loosely took 1 second
for wait time. I'll fix it later. (The reason I drastically changed
the code is that I wanted to implement the fileset management as
single function, and I was worried that if pipe or console
was always available, socket may not be processed any time)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9193 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r-- | win32/win32.c | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/win32/win32.c b/win32/win32.c index 02983e19e3..10fc5b3a04 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1969,6 +1969,42 @@ is_readable_pipe(SOCKET sock) /* call this for pipe only */ return ret; } +static int +is_console(SOCKET sock) /* DONT call this for SOCKET! */ +{ + int ret; + DWORD n = 0; + INPUT_RECORD ir; + + RUBY_CRITICAL( + ret = (PeekConsoleInput((HANDLE)sock, &ir, 1, &n)) + ); + + return ret; +} + +static int +is_readable_console(SOCKET sock) /* call this for console only */ +{ + int ret = 0; + DWORD n = 0; + INPUT_RECORD ir; + + RUBY_CRITICAL( + if (PeekConsoleInput((HANDLE)sock, &ir, 1, &n) && n > 0) { + if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown && + ir.Event.KeyEvent.uChar.AsciiChar) { + ret = 1; + } + else { + ReadConsoleInput((HANDLE)sock, &ir, 1, &n); + } + } + ); + + return ret; +} + static long do_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *timeout) @@ -1995,6 +2031,7 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, { long r; fd_set pipe_rd; + fd_set cons_rd; fd_set unknown_rd; fd_set unknown_wr; #ifdef USE_INTERRUPT_WINSOCK @@ -2010,12 +2047,14 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, } pipe_rd.fd_count = 0; + cons_rd.fd_count = 0; unknown_rd.fd_count = 0; unknown_wr.fd_count = 0; extract_fd(&unknown_rd, rd, is_not_socket); /* must exclude socket first! */ extract_fd(&unknown_wr, wr, is_not_socket); /* must exclude socket first! */ extract_fd(&pipe_rd, &unknown_rd, is_pipe); /* don't call is_pipe for socket! */ + extract_fd(&cons_rd, &unknown_rd, is_console); /* probably ditto */ if (unknown_rd.fd_count + unknown_wr.fd_count) { // assume unknown handles are always readable/writable @@ -2043,12 +2082,14 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, #endif /* USE_INTERRUPT_WINSOCK */ RUBY_CRITICAL( - if (pipe_rd.fd_count) { + if (pipe_rd.fd_count || cons_rd.fd_count) { long sec = timeout ? timeout->tv_sec + 1 : 0/*dummy*/; while (!timeout || sec--) { fd_set buf; buf.fd_count = 0; // pipe extract_fd(&buf, &pipe_rd, is_readable_pipe); + // console + extract_fd(&buf, &cons_rd, is_readable_console); // socket if (buf.fd_count) { struct timeval val; val.tv_sec = 0; val.tv_usec = 0; |