mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
cd796c609f
commit
82b2e80120
2 changed files with 20 additions and 60 deletions
|
@ -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().
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue