ruby-changes:21540
From: akr <ko1@a...>
Date: Mon, 31 Oct 2011 23:38:59 +0900 (JST)
Subject: [ruby-changes:21540] akr:r33589 (trunk): * ext/socket/init.c (rsock_socket): use SOCK_CLOEXEC if available.
akr 2011-10-31 23:38:50 +0900 (Mon, 31 Oct 2011) New Revision: 33589 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33589 Log: * ext/socket/init.c (rsock_socket): use SOCK_CLOEXEC if available. Modified files: trunk/ChangeLog trunk/ext/socket/init.c Index: ChangeLog =================================================================== --- ChangeLog (revision 33588) +++ ChangeLog (revision 33589) @@ -1,3 +1,7 @@ +Mon Oct 31 23:31:53 2011 Tanaka Akira <akr@f...> + + * ext/socket/init.c (rsock_socket): use SOCK_CLOEXEC if available. + Mon Oct 31 21:47:44 2011 NARUSE, Yui <naruse@r...> * io.c (rb_cloexec_pipe): NetBSD 6.0 will support pipe2(2), Index: ext/socket/init.c =================================================================== --- ext/socket/init.c (revision 33588) +++ ext/socket/init.c (revision 33589) @@ -240,19 +240,38 @@ } int -rsock_socket(int domain, int type, int proto) +rsock_socket(int domain, int type0, int proto) { - int fd; + int fd, type; +#ifdef SOCK_CLOEXEC + static int try_sock_cloexec = 1; + if (try_sock_cloexec) + type = type0|SOCK_CLOEXEC; + else + type = type0; + retry_without_sock_cloexec:; +#else + type = type0; +#endif + fd = socket(domain, type, proto); if (fd < 0) { +#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) { + try_sock_cloexec = 0; + type = type0; + goto retry_without_sock_cloexec; + } +#endif if (errno == EMFILE || errno == ENFILE) { rb_gc(); fd = socket(domain, type, proto); } } if (0 <= fd) - rb_fd_fix_cloexec(fd); + rb_update_max_fd(fd); return fd; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/