зеркало из https://github.com/github/ruby.git
* ext/socket/init.c (cloexec_accept): new function to use accept4 if
available. (rsock_s_accept_nonblock): use cloexec_accept. (accept_blocking): ditto. * ext/socket/extconf.rb: check accept4. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
24176a8d5d
Коммит
5dbc3d1e79
|
@ -1,3 +1,12 @@
|
|||
Tue Nov 1 08:24:40 2011 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/socket/init.c (cloexec_accept): new function to use accept4 if
|
||||
available.
|
||||
(rsock_s_accept_nonblock): use cloexec_accept.
|
||||
(accept_blocking): ditto.
|
||||
|
||||
* ext/socket/extconf.rb: check accept4.
|
||||
|
||||
Tue Nov 1 07:31:55 2011 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/socket/ancdata.c (nogvl_recvmsg_func): use MSG_CMSG_CLOEXEC if
|
||||
|
|
|
@ -397,6 +397,8 @@ EOF
|
|||
end
|
||||
end
|
||||
|
||||
have_func("accept4")
|
||||
|
||||
$objs = [
|
||||
"init.#{$OBJEXT}",
|
||||
"constants.#{$OBJEXT}",
|
||||
|
|
|
@ -463,6 +463,30 @@ make_fd_nonblock(int fd)
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
cloexec_accept(int socket, struct sockaddr *address, socklen_t *address_len)
|
||||
{
|
||||
int ret;
|
||||
#ifdef HAVE_ACCEPT4
|
||||
static int try_accept4 = 1;
|
||||
if (try_accept4) {
|
||||
ret = accept4(socket, address, address_len, SOCK_CLOEXEC);
|
||||
/* accept4 is available since Linux 2.6.28, glibc 2.10. */
|
||||
if (ret == -1 && errno == ENOSYS) {
|
||||
try_accept4 = 0;
|
||||
ret = accept(socket, address, address_len);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ret = accept(socket, address, address_len);
|
||||
}
|
||||
#else
|
||||
ret = accept(socket, address, address_len);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
VALUE
|
||||
rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len)
|
||||
{
|
||||
|
@ -470,7 +494,7 @@ rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, s
|
|||
|
||||
rb_secure(3);
|
||||
rb_io_set_nonblock(fptr);
|
||||
fd2 = accept(fptr->fd, (struct sockaddr*)sockaddr, len);
|
||||
fd2 = cloexec_accept(fptr->fd, (struct sockaddr*)sockaddr, len);
|
||||
if (fd2 < 0) {
|
||||
switch (errno) {
|
||||
case EAGAIN:
|
||||
|
@ -500,7 +524,7 @@ static VALUE
|
|||
accept_blocking(void *data)
|
||||
{
|
||||
struct accept_arg *arg = data;
|
||||
return (VALUE)accept(arg->fd, arg->sockaddr, arg->len);
|
||||
return (VALUE)cloexec_accept(arg->fd, arg->sockaddr, arg->len);
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
|
Загрузка…
Ссылка в новой задаче