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

* ext/socket/init.c (rsock_socket0): extract single socket() call with

CLOEXEC handling from rsock_socket.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33637 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2011-11-05 06:46:02 +00:00
parent d05202a596
commit 0e68c46e2d
2 changed files with 32 additions and 18 deletions

View file

@ -1,3 +1,8 @@
Sat Nov 5 15:45:04 2011 Tanaka Akira <akr@fsij.org>
* ext/socket/init.c (rsock_socket0): extract single socket() call with
CLOEXEC handling from rsock_socket.
Sat Nov 5 11:18:12 2011 Tanaka Akira <akr@fsij.org>
* ext/socket/socket.c (rsock_socketpair0): don't clear

View file

@ -239,10 +239,10 @@ rsock_s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type
return rb_assoc_new(str, addr);
}
int
rsock_socket(int domain, int type0, int proto)
static int
rsock_socket0(int domain, int type0, int proto)
{
int fd, type;
int ret, type;
#ifdef SOCK_CLOEXEC
static int try_sock_cloexec = 1;
@ -255,8 +255,9 @@ rsock_socket(int domain, int type0, int proto)
type = type0;
#endif
fd = socket(domain, type, proto);
if (fd < 0) {
ret = socket(domain, type, proto);
if (ret == -1) {
#ifdef SOCK_CLOEXEC
/* SOCK_CLOEXEC is available since Linux 2.6.27. Linux 2.6.18 fails with EINVAL */
if (try_sock_cloexec && errno == EINVAL) {
@ -265,21 +266,29 @@ rsock_socket(int domain, int type0, int proto)
goto retry_without_sock_cloexec;
}
#endif
if (errno == EMFILE || errno == ENFILE) {
rb_gc();
fd = socket(domain, type, proto);
}
return -1;
}
rb_fd_fix_cloexec(ret);
return ret;
}
int
rsock_socket(int domain, int type, int proto)
{
int fd;
fd = rsock_socket0(domain, type, proto);
if (fd < 0) {
if (errno == EMFILE || errno == ENFILE) {
rb_gc();
fd = rsock_socket0(domain, type, proto);
}
}
#ifdef SOCK_CLOEXEC
if (0 <= fd)
if (try_sock_cloexec)
rb_update_max_fd(fd);
else
rb_fd_fix_cloexec(fd);
#else
if (0 <= fd)
rb_fd_fix_cloexec(fd);
#endif
rb_update_max_fd(fd);
return fd;
}