ruby-changes:11483
From: matz <ko1@a...>
Date: Wed, 1 Apr 2009 13:57:50 +0900 (JST)
Subject: [ruby-changes:11483] Ruby:r23109 (trunk): * thread.c (rb_thread_fd_select): new function to call select
matz 2009-04-01 13:56:51 +0900 (Wed, 01 Apr 2009) New Revision: 23109 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23109 Log: * thread.c (rb_thread_fd_select): new function to call select using rb_fdset_t. * io.c (select_internal): use rb_thread_fd_select instead of rb_thread_select. based on the patch from Kengo Matsuyama. [ruby-dev:38221] Modified files: trunk/ChangeLog trunk/include/ruby/intern.h trunk/io.c trunk/thread.c Index: include/ruby/intern.h =================================================================== --- include/ruby/intern.h (revision 23108) +++ include/ruby/intern.h (revision 23109) @@ -244,6 +244,7 @@ #define rb_fd_clr(n, f) FD_CLR(n, f) #define rb_fd_isset(n, f) FD_ISSET(n, f) #define rb_fd_copy(d, s, n) (*(d) = *(s)) +#define rb_fd_resize(n, f) (void)(f) #define rb_fd_ptr(f) (f) #define rb_fd_init(f) FD_ZERO(f) #define rb_fd_term(f) (void)(f) @@ -327,6 +328,7 @@ void rb_thread_signal_raise(void *, int); void rb_thread_signal_exit(void *); int rb_thread_select(int, fd_set *, fd_set *, fd_set *, struct timeval *); +int rb_thread_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *); void rb_thread_wait_for(struct timeval); VALUE rb_thread_current(void); VALUE rb_thread_main(void); Index: ChangeLog =================================================================== --- ChangeLog (revision 23108) +++ ChangeLog (revision 23109) @@ -1,3 +1,12 @@ +Wed Apr 1 13:46:20 2009 Yukihiro Matsumoto <matz@r...> + + * thread.c (rb_thread_fd_select): new function to call select + using rb_fdset_t. + + * io.c (select_internal): use rb_thread_fd_select instead of + rb_thread_select. based on the patch from Kengo Matsuyama. + [ruby-dev:38221] + Wed Apr 1 13:16:19 2009 Yukihiro Matsumoto <matz@r...> * process.c (rb_f_sleep): RDoc disambiguation. [ruby-talk:332632] Index: io.c =================================================================== --- io.c (revision 23108) +++ io.c (revision 23109) @@ -6635,7 +6635,7 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fdset_t *fds) { VALUE res, list; - fd_set *rp, *wp, *ep; + rb_fdset_t *rp, *wp, *ep; rb_io_t *fptr; long i; int max = 0, n; @@ -6658,7 +6658,7 @@ timerec.tv_sec = timerec.tv_usec = 0; tp = &timerec; } - rp = rb_fd_ptr(&fds[0]); + rp = &fds[0]; } else rp = 0; @@ -6671,7 +6671,7 @@ rb_fd_set(fptr->fd, &fds[1]); if (max < fptr->fd) max = fptr->fd; } - wp = rb_fd_ptr(&fds[1]); + wp = &fds[1]; } else wp = 0; @@ -6690,7 +6690,7 @@ if (max < fptr->fd) max = fptr->fd; } } - ep = rb_fd_ptr(&fds[2]); + ep = &fds[2]; } else { ep = 0; @@ -6698,7 +6698,7 @@ max++; - n = rb_thread_select(max, rp, wp, ep, tp); + n = rb_thread_fd_select(max, rp, wp, ep, tp); if (n < 0) { rb_sys_fail(0); } Index: thread.c =================================================================== --- thread.c (revision 23108) +++ thread.c (revision 23109) @@ -2490,6 +2490,37 @@ } +int +rb_thread_fd_select(int max, rb_fdset_t * read, rb_fdset_t * write, rb_fdset_t * except, + struct timeval *timeout) +{ + fd_set *r = NULL, *w = NULL, *e = NULL; + + if (!read && !write && !except) { + if (!timeout) { + rb_thread_sleep_forever(); + return 0; + } + rb_thread_wait_for(*timeout); + return 0; + } + + if (read) { + rb_fd_resize(max - 1, read); + r = rb_fd_ptr(read); + } + if (write) { + rb_fd_resize(max - 1, write); + w = rb_fd_ptr(write); + } + if (except) { + rb_fd_resize(max - 1, except); + e = rb_fd_ptr(except); + } + return do_select(max, r, w, e, timeout); +} + + /* * for GC */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/