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

* thread.c (do_select): Change arugment type to rb_fdset_t.

Now do_select() is free from unexpected hangup if
  HAVE_RB_FD_INIT=1 [Bug ]

* thread.c (rb_thread_fd_select, rb_thread_wait_fd_rw):
  adapt new argument type.

* thread.c (rb_thread_select): make dummy implementation.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31396 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kosaki 2011-04-30 11:23:08 +00:00
parent 225fa965bc
commit 3c68095b8a
2 changed files with 48 additions and 27 deletions

View file

@ -1,3 +1,14 @@
Sat Apr 30 20:18:43 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* thread.c (do_select): Change arugment type to rb_fdset_t.
Now do_select() is free from unexpected hangup if
HAVE_RB_FD_INIT=1 [Bug #4636]
* thread.c (rb_thread_fd_select, rb_thread_wait_fd_rw):
adapt new argument type.
* thread.c (rb_thread_select): make dummy implementation.
Sat Apr 30 20:16:53 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com> Sat Apr 30 20:16:53 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* thread.c (rb_fd_copy): Change function argument. Now * thread.c (rb_fd_copy): Change function argument. Now

View file

@ -2497,13 +2497,13 @@ subtract_tv(struct timeval *rest, const struct timeval *wait)
#endif #endif
static int static int
do_select(int n, fd_set *read, fd_set *write, fd_set *except, do_select(int n, rb_fdset_t *read, rb_fdset_t *write, rb_fdset_t *except,
struct timeval *timeout) struct timeval *timeout)
{ {
int result, lerrno; int result, lerrno;
fd_set UNINITIALIZED_VAR(orig_read); rb_fdset_t UNINITIALIZED_VAR(orig_read);
fd_set UNINITIALIZED_VAR(orig_write); rb_fdset_t UNINITIALIZED_VAR(orig_write);
fd_set UNINITIALIZED_VAR(orig_except); rb_fdset_t UNINITIALIZED_VAR(orig_except);
double limit = 0; double limit = 0;
struct timeval wait_rest; struct timeval wait_rest;
# if defined(__CYGWIN__) || defined(_WIN32) # if defined(__CYGWIN__) || defined(_WIN32)
@ -2522,9 +2522,18 @@ do_select(int n, fd_set *read, fd_set *write, fd_set *except,
timeout = &wait_rest; timeout = &wait_rest;
} }
if (read) orig_read = *read; if (read) {
if (write) orig_write = *write; rb_fd_init(&orig_read);
if (except) orig_except = *except; rb_fd_copy(&orig_read, read);
}
if (write) {
rb_fd_init(&orig_write);
rb_fd_copy(&orig_write, write);
}
if (except) {
rb_fd_init(&orig_except);
rb_fd_copy(&orig_except, except);
}
retry: retry:
lerrno = 0; lerrno = 0;
@ -2541,13 +2550,16 @@ do_select(int n, fd_set *read, fd_set *write, fd_set *except,
wait = (timeout == 0 || cmp_tv(&wait_100ms, timeout) < 0) ? &wait_100ms : timeout; wait = (timeout == 0 || cmp_tv(&wait_100ms, timeout) < 0) ? &wait_100ms : timeout;
BLOCKING_REGION({ BLOCKING_REGION({
do { do {
result = select(n, read, write, except, wait); result = rb_fd_select(n, read, write, except, wait);
if (result < 0) lerrno = errno; if (result < 0) lerrno = errno;
if (result != 0) break; if (result != 0) break;
if (read) *read = orig_read; if (read)
if (write) *write = orig_write; rb_fd_copy(read, &orig_read);
if (except) *except = orig_except; if (write)
rb_fd_copy(write, &orig_write);
if (except)
rb_fd_copy(except, &orig_except);
if (timeout) { if (timeout) {
struct timeval elapsed; struct timeval elapsed;
gettimeofday(&elapsed, NULL); gettimeofday(&elapsed, NULL);
@ -2565,7 +2577,7 @@ do_select(int n, fd_set *read, fd_set *write, fd_set *except,
} }
#else #else
BLOCKING_REGION({ BLOCKING_REGION({
result = select(n, read, write, except, timeout); result = rb_fd_select(n, read, write, except, timeout);
if (result < 0) lerrno = errno; if (result < 0) lerrno = errno;
}, ubf_select, GET_THREAD()); }, ubf_select, GET_THREAD());
#endif #endif
@ -2578,9 +2590,12 @@ do_select(int n, fd_set *read, fd_set *write, fd_set *except,
#ifdef ERESTART #ifdef ERESTART
case ERESTART: case ERESTART:
#endif #endif
if (read) *read = orig_read; if (read)
if (write) *write = orig_write; rb_fd_copy(read, &orig_read);
if (except) *except = orig_except; if (write)
rb_fd_copy(write, &orig_write);
if (except)
rb_fd_copy(except, &orig_except);
if (timeout) { if (timeout) {
double d = limit - timeofday(); double d = limit - timeofday();
@ -2615,10 +2630,10 @@ rb_thread_wait_fd_rw(int fd, int read)
FD_SET(fd, &set); FD_SET(fd, &set);
if (read) { if (read) {
result = do_select(fd + 1, rb_fd_ptr(&set), 0, 0, 0); result = do_select(fd + 1, &set, 0, 0, 0);
} }
else { else {
result = do_select(fd + 1, 0, rb_fd_ptr(&set), 0, 0); result = do_select(fd + 1, 0, &set, 0, 0);
} }
rb_fd_term(&set); rb_fd_term(&set);
@ -2657,7 +2672,7 @@ rb_thread_select(int max, fd_set * read, fd_set * write, fd_set * except,
return 0; return 0;
} }
else { else {
return do_select(max, read, write, except, timeout); return select(max, read, write, except, timeout);
} }
} }
@ -2666,8 +2681,6 @@ int
rb_thread_fd_select(int max, rb_fdset_t * read, rb_fdset_t * write, rb_fdset_t * except, rb_thread_fd_select(int max, rb_fdset_t * read, rb_fdset_t * write, rb_fdset_t * except,
struct timeval *timeout) struct timeval *timeout)
{ {
fd_set *r = NULL, *w = NULL, *e = NULL;
if (!read && !write && !except) { if (!read && !write && !except) {
if (!timeout) { if (!timeout) {
rb_thread_sleep_forever(); rb_thread_sleep_forever();
@ -2678,18 +2691,15 @@ rb_thread_fd_select(int max, rb_fdset_t * read, rb_fdset_t * write, rb_fdset_t *
} }
if (read) { if (read) {
rb_fd_resize(max - 1, read); rb_fd_resize(max - 1, read);
r = rb_fd_ptr(read);
} }
if (write) { if (write) {
rb_fd_resize(max - 1, write); rb_fd_resize(max - 1, write);
w = rb_fd_ptr(write);
} }
if (except) { if (except) {
rb_fd_resize(max - 1, except); rb_fd_resize(max - 1, except);
e = rb_fd_ptr(except);
} }
return do_select(max, r, w, e, timeout); return do_select(max, read, write, except, timeout);
} }