1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
ocean 2005-09-17 04:53:26 +00:00
parent 846b1c35e5
commit aa21055faf
2 changed files with 51 additions and 1 deletions

View file

@ -1,3 +1,12 @@
Sat Sep 17 13:45:22 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* 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)
Sat Sep 17 11:24:16 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp> Sat Sep 17 11:24:16 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* win32/win32.c (rb_w32_select): select for socket didn't work. * win32/win32.c (rb_w32_select): select for socket didn't work.

View file

@ -1969,6 +1969,42 @@ is_readable_pipe(SOCKET sock) /* call this for pipe only */
return ret; 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 static long
do_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, do_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
struct timeval *timeout) struct timeval *timeout)
@ -1995,6 +2031,7 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
{ {
long r; long r;
fd_set pipe_rd; fd_set pipe_rd;
fd_set cons_rd;
fd_set unknown_rd; fd_set unknown_rd;
fd_set unknown_wr; fd_set unknown_wr;
#ifdef USE_INTERRUPT_WINSOCK #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; pipe_rd.fd_count = 0;
cons_rd.fd_count = 0;
unknown_rd.fd_count = 0; unknown_rd.fd_count = 0;
unknown_wr.fd_count = 0; unknown_wr.fd_count = 0;
extract_fd(&unknown_rd, rd, is_not_socket); /* must exclude socket first! */ 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(&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(&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) { if (unknown_rd.fd_count + unknown_wr.fd_count) {
// assume unknown handles are always readable/writable // 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 */ #endif /* USE_INTERRUPT_WINSOCK */
RUBY_CRITICAL( 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*/; long sec = timeout ? timeout->tv_sec + 1 : 0/*dummy*/;
while (!timeout || sec--) { while (!timeout || sec--) {
fd_set buf; buf.fd_count = 0; fd_set buf; buf.fd_count = 0;
// pipe // pipe
extract_fd(&buf, &pipe_rd, is_readable_pipe); extract_fd(&buf, &pipe_rd, is_readable_pipe);
// console
extract_fd(&buf, &cons_rd, is_readable_console);
// socket // socket
if (buf.fd_count) { if (buf.fd_count) {
struct timeval val; val.tv_sec = 0; val.tv_usec = 0; struct timeval val; val.tv_sec = 0; val.tv_usec = 0;