diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-06-03 14:23:17 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-06-03 14:23:17 +0000 |
commit | c9d126aec990acb56dfa87b67e9fc312f82da91d (patch) | |
tree | 23d741448c4f9a2b75c2cd876423ed27db4edd8e /ext | |
parent | f0ede6b31cc81671d231a92db8b3e87127f4eb24 (diff) | |
download | ruby-c9d126aec990acb56dfa87b67e9fc312f82da91d.tar.gz |
* intern.h (rb_fdset_t): deal with fd bit sets over FD_SETSIZE.
fixed: [ruby-dev:26187]
* eval.c (rb_fd_init, rb_fd_term, rb_fd_zero, rb_fd_set, rb_fd_clr,
rb_fd_isset, rb_fd_copy): ditto.
* io.c (rb_io_wait_readable, rb_io_wait_writable, rb_f_select): ditto.
* ext/io/wait/wait.c (io_wait): ditto.
* ext/socket/socket.c (wait_connectable, unix_recv_io): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8552 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/io/wait/wait.c | 37 | ||||
-rw-r--r-- | ext/socket/socket.c | 77 |
2 files changed, 83 insertions, 31 deletions
diff --git a/ext/io/wait/wait.c b/ext/io/wait/wait.c index df8d24c29b..fcb3bcfe42 100644 --- a/ext/io/wait/wait.c +++ b/ext/io/wait/wait.c @@ -50,6 +50,23 @@ io_ready_p(io) return Qnil; } +struct wait_readable_arg { + rb_fdset_t fds; + struct timeval *timeout; +}; + +#ifdef HAVE_RB_FD_INIT +static VALUE +wait_readable(p) + VALUE p; +{ + struct wait_readable_arg *arg = (struct wait_readable_arg *)p; + rb_fdset_t *fds = &arg->fds; + + return (VALUE)rb_thread_select(rb_fd_max(fds), rb_fd_ptr(fds), NULL, NULL, arg->timeout); +} +#endif + /* =begin --- IO#wait([timeout]) @@ -64,27 +81,33 @@ io_wait(argc, argv, io) VALUE io; { OpenFile *fptr; - fd_set rd; + struct wait_readable_arg arg; int fd, n; VALUE timeout; - struct timeval *tp, timerec; + struct timeval timerec; GetOpenFile(io, fptr); rb_io_check_readable(fptr); rb_scan_args(argc, argv, "01", &timeout); if (NIL_P(timeout)) { - tp = 0; + arg.timeout = 0; } else { timerec = rb_time_interval(timeout); - tp = &timerec; + arg.timeout = &timerec; } if (rb_io_read_pending(fptr)) return Qtrue; fd = fptr->fd; - FD_ZERO(&rd); - FD_SET(fd, &rd); - if (rb_thread_select(fd + 1, &rd, NULL, NULL, tp) < 0) + rb_fd_init(&arg.fds); + rb_fd_set(fd, &arg.fds); +#ifdef HAVE_RB_FD_INIT + n = (int)rb_ensure(wait_readable, (VALUE)&arg, + (VALUE (*)_((VALUE)))rb_fd_term, (VALUE)&arg.fds); +#else + n = rb_thread_select(fd + 1, rb_fd_ptr(&rd), NULL, NULL, tp) +#endif + if (n < 0) rb_sys_fail(0); rb_io_check_closed(fptr); if (ioctl(fptr->fd, FIONREAD, &n)) rb_sys_fail(0); diff --git a/ext/socket/socket.c b/ext/socket/socket.c index 9383580bdf..d4fd620a00 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -888,26 +888,25 @@ ruby_socket(domain, type, proto) } static int -wait_connectable(fd) +wait_connectable0(fd, fds_w, fds_e) int fd; + rb_fdset_t *fds_w, *fds_e; { int sockerr, sockerrlen; - fd_set fds_w; - fd_set fds_e; for (;;) { - FD_ZERO(&fds_w); - FD_ZERO(&fds_e); + rb_fd_zero(fds_w); + rb_fd_zero(fds_e); - FD_SET(fd, &fds_w); - FD_SET(fd, &fds_e); + rb_fd_set(fd, fds_w); + rb_fd_set(fd, fds_e); - rb_thread_select(fd+1, 0, &fds_w, &fds_e, 0); + rb_thread_select(fd+1, 0, rb_fd_ptr(fds_w), rb_fd_ptr(fds_e), 0); - if (FD_ISSET(fd, &fds_w)) { + if (rb_fd_isset(fd, fds_w)) { return 0; } - else if (FD_ISSET(fd, &fds_e)) { + else if (rb_fd_isset(fd, fds_e)) { sockerrlen = sizeof(sockerr); if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&sockerr, &sockerrlen) == 0) { @@ -922,6 +921,49 @@ wait_connectable(fd) return 0; } +struct wait_connectable_arg { + int fd; + rb_fdset_t fds_w; + rb_fdset_t fds_e; +}; + +#ifdef HAVE_RB_FD_INIT +static VALUE +try_wait_connectable(arg) + VALUE arg; +{ + struct wait_connectable_arg *p = (struct wait_connectable_arg *)arg; + return (VALUE)wait_connectable0(p->fd, &p->fds_w, &p->fds_e); +} + +static VALUE +wait_connectable_ensure(arg) + VALUE arg; +{ + struct wait_connectable_arg *p = (struct wait_connectable_arg *)arg; + rb_fd_term(&p->fds_w); + rb_fd_term(&p->fds_e); + return Qnil; +} +#endif + +static int +wait_connectable(fd) + int fd; +{ + struct wait_connectable_arg arg; + + rb_fd_init(&arg.fds_w); + rb_fd_init(&arg.fds_e); +#ifdef HAVE_RB_FD_INIT + arg.fd = fd; + return (int)rb_ensure(try_wait_connectable, (VALUE)&arg, + wait_connectable_ensure,(VALUE)&arg); +#else + return wait_connectable0(fd, &arg.fds_w, &arg.fds_e); +#endif +} + #ifdef __CYGWIN__ #define WAIT_IN_PROGRESS 10 #endif @@ -1734,19 +1776,6 @@ unix_send_io(sock, val) #endif } -#if defined(HAVE_RECVMSG) && (FD_PASSING_BY_MSG_CONTROL || FD_PASSING_BY_MSG_ACCRIGHTS) -static void -thread_read_select(fd) - int fd; -{ - fd_set fds; - - FD_ZERO(&fds); - FD_SET(fd, &fds); - rb_thread_select(fd+1, &fds, 0, 0, 0); -} -#endif - static VALUE unix_recv_io(argc, argv, sock) int argc; @@ -1776,7 +1805,7 @@ unix_recv_io(argc, argv, sock) GetOpenFile(sock, fptr); - thread_read_select(fptr->fd); + rb_io_wait_readable(fptr->fd); msg.msg_name = NULL; msg.msg_namelen = 0; |