mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23109 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9be62b3b1a
commit
d98da36b8c
4 changed files with 47 additions and 5 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
Wed Apr 1 13:46:20 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Wed Apr 1 13:16:19 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* process.c (rb_f_sleep): RDoc disambiguation. [ruby-talk:332632]
|
* process.c (rb_f_sleep): RDoc disambiguation. [ruby-talk:332632]
|
||||||
|
|
|
@ -244,6 +244,7 @@ typedef fd_set rb_fdset_t;
|
||||||
#define rb_fd_clr(n, f) FD_CLR(n, f)
|
#define rb_fd_clr(n, f) FD_CLR(n, f)
|
||||||
#define rb_fd_isset(n, f) FD_ISSET(n, f)
|
#define rb_fd_isset(n, f) FD_ISSET(n, f)
|
||||||
#define rb_fd_copy(d, s, n) (*(d) = *(s))
|
#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_ptr(f) (f)
|
||||||
#define rb_fd_init(f) FD_ZERO(f)
|
#define rb_fd_init(f) FD_ZERO(f)
|
||||||
#define rb_fd_term(f) (void)(f)
|
#define rb_fd_term(f) (void)(f)
|
||||||
|
@ -327,6 +328,7 @@ VALUE rb_thread_create(VALUE (*)(ANYARGS), void*);
|
||||||
void rb_thread_signal_raise(void *, int);
|
void rb_thread_signal_raise(void *, int);
|
||||||
void rb_thread_signal_exit(void *);
|
void rb_thread_signal_exit(void *);
|
||||||
int rb_thread_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
|
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);
|
void rb_thread_wait_for(struct timeval);
|
||||||
VALUE rb_thread_current(void);
|
VALUE rb_thread_current(void);
|
||||||
VALUE rb_thread_main(void);
|
VALUE rb_thread_main(void);
|
||||||
|
|
10
io.c
10
io.c
|
@ -6635,7 +6635,7 @@ static VALUE
|
||||||
select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fdset_t *fds)
|
select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fdset_t *fds)
|
||||||
{
|
{
|
||||||
VALUE res, list;
|
VALUE res, list;
|
||||||
fd_set *rp, *wp, *ep;
|
rb_fdset_t *rp, *wp, *ep;
|
||||||
rb_io_t *fptr;
|
rb_io_t *fptr;
|
||||||
long i;
|
long i;
|
||||||
int max = 0, n;
|
int max = 0, n;
|
||||||
|
@ -6658,7 +6658,7 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fd
|
||||||
timerec.tv_sec = timerec.tv_usec = 0;
|
timerec.tv_sec = timerec.tv_usec = 0;
|
||||||
tp = &timerec;
|
tp = &timerec;
|
||||||
}
|
}
|
||||||
rp = rb_fd_ptr(&fds[0]);
|
rp = &fds[0];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
rp = 0;
|
rp = 0;
|
||||||
|
@ -6671,7 +6671,7 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fd
|
||||||
rb_fd_set(fptr->fd, &fds[1]);
|
rb_fd_set(fptr->fd, &fds[1]);
|
||||||
if (max < fptr->fd) max = fptr->fd;
|
if (max < fptr->fd) max = fptr->fd;
|
||||||
}
|
}
|
||||||
wp = rb_fd_ptr(&fds[1]);
|
wp = &fds[1];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
wp = 0;
|
wp = 0;
|
||||||
|
@ -6690,7 +6690,7 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fd
|
||||||
if (max < fptr->fd) max = fptr->fd;
|
if (max < fptr->fd) max = fptr->fd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ep = rb_fd_ptr(&fds[2]);
|
ep = &fds[2];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ep = 0;
|
ep = 0;
|
||||||
|
@ -6698,7 +6698,7 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fd
|
||||||
|
|
||||||
max++;
|
max++;
|
||||||
|
|
||||||
n = rb_thread_select(max, rp, wp, ep, tp);
|
n = rb_thread_fd_select(max, rp, wp, ep, tp);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
rb_sys_fail(0);
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
|
|
31
thread.c
31
thread.c
|
@ -2490,6 +2490,37 @@ rb_thread_select(int max, fd_set * read, fd_set * write, fd_set * except,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
* for GC
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue