summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-04 01:12:04 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-04 01:12:04 +0000
commit82b2e8012048cdc6f6ee7659fdb25ffa53945d02 (patch)
treea637fee6c8631aac2e03ed90c869d9ad3bb78eda
parentcd796c609fec41b412a78bd742c723b1d8319c61 (diff)
downloadruby-82b2e8012048cdc6f6ee7659fdb25ffa53945d02.tar.gz
* ext/socket/init.c (wait_connectable): use rb_wait_for_single_fd().
The patch was written by Eric Wong. [Ruby 1.9 - Feature #4531] * ext/socket/init.c (try_wait_connectable, wait_connectable_ensure): removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31422 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--ext/socket/init.c72
2 files changed, 20 insertions, 60 deletions
diff --git a/ChangeLog b/ChangeLog
index 4b40b55aaa..0a8278f455 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Wed May 4 10:10:28 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
+
+ * ext/socket/init.c (wait_connectable): use rb_wait_for_single_fd().
+ The patch was written by Eric Wong. [Ruby 1.9 - Feature #4531]
+
+ * ext/socket/init.c (try_wait_connectable, wait_connectable_ensure):
+ removed.
+
Wed May 4 10:07:48 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* ext/io/wait/wait.c (io_wait): use rb_wait_for_single_fd().
diff --git a/ext/socket/init.c b/ext/socket/init.c
index ee88e81bae..4c32ab4720 100644
--- a/ext/socket/init.c
+++ b/ext/socket/init.c
@@ -254,76 +254,28 @@ rsock_socket(int domain, int type, int proto)
}
static int
-wait_connectable0(int fd, rb_fdset_t *fds_w, rb_fdset_t *fds_e)
+wait_connectable(int fd)
{
int sockerr;
socklen_t sockerrlen;
+ int r;
for (;;) {
- rb_fd_zero(fds_w);
- rb_fd_zero(fds_e);
-
- rb_fd_set(fd, fds_w);
- rb_fd_set(fd, fds_e);
-
- rb_thread_fd_select(fd+1, 0, fds_w, fds_e, 0);
-
- if (rb_fd_isset(fd, fds_w)) {
+ r = rb_wait_for_single_fd(fd, RB_WAITFD_OUT|RB_WAITFD_PRI, NULL);
+ if ((r > 0) && (r & RB_WAITFD_OUT))
return 0;
+
+ sockerrlen = (socklen_t)sizeof(sockerr);
+ if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&sockerr,
+ &sockerrlen) == 0) {
+ if (sockerr == 0)
+ continue; /* workaround for winsock */
+ errno = sockerr;
}
- else if (rb_fd_isset(fd, fds_e)) {
- sockerrlen = (socklen_t)sizeof(sockerr);
- if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&sockerr,
- &sockerrlen) == 0) {
- if (sockerr == 0)
- continue; /* workaround for winsock */
- errno = sockerr;
- }
- return -1;
- }
+ return -1;
}
}
-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(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(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(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