mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/socket/socket.c (rsock_socketpair): use SOCK_CLOEXEC if
available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
17f068b6a6
commit
ee5ae134dd
2 changed files with 31 additions and 5 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Tue Nov 1 05:59:41 2011 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* ext/socket/socket.c (rsock_socketpair): use SOCK_CLOEXEC if
|
||||||
|
available.
|
||||||
|
|
||||||
Tue Nov 1 02:56:17 2011 NAKAMURA Usaku <usa@ruby-lang.org>
|
Tue Nov 1 02:56:17 2011 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* ruby.c (load_file_internal): convert the encoding of load path if
|
* ruby.c (load_file_internal): convert the encoding of load path if
|
||||||
|
|
|
@ -78,14 +78,35 @@ pair_yield(VALUE pair)
|
||||||
#if defined HAVE_SOCKETPAIR
|
#if defined HAVE_SOCKETPAIR
|
||||||
|
|
||||||
static int
|
static int
|
||||||
rsock_socketpair(int domain, int type, int protocol, int sv[2])
|
rsock_socketpair(int domain, int type0, int protocol, int sv[2])
|
||||||
{
|
{
|
||||||
int ret;
|
int ret, 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
|
||||||
|
|
||||||
ret = socketpair(domain, type, protocol, sv);
|
ret = socketpair(domain, type, protocol, sv);
|
||||||
if (ret < 0 && (errno == EMFILE || errno == ENFILE)) {
|
if (ret < 0) {
|
||||||
rb_gc();
|
#ifdef SOCK_CLOEXEC
|
||||||
ret = socketpair(domain, type, protocol, sv);
|
/* 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();
|
||||||
|
ret = socketpair(domain, type, protocol, sv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Add table
Reference in a new issue