* ext/socket/socket.c (rsock_socketpair): extracted from

rsock_sock_s_socketpair.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2011-10-31 14:49:57 +00:00
parent 1a8fbff3db
commit 8ce4a284e4
2 changed files with 21 additions and 5 deletions

View File

@ -1,3 +1,8 @@
Mon Oct 31 23:49:38 2011 Tanaka Akira <akr@fsij.org>
* ext/socket/socket.c (rsock_socketpair): extracted from
rsock_sock_s_socketpair.
Mon Oct 31 23:31:53 2011 Tanaka Akira <akr@fsij.org>
* ext/socket/init.c (rsock_socket): use SOCK_CLOEXEC if available.

View File

@ -76,6 +76,21 @@ pair_yield(VALUE pair)
#endif
#if defined HAVE_SOCKETPAIR
static int
rsock_socketpair(int domain, int type, int protocol, int sv[2])
{
int ret;
ret = socketpair(domain, type, protocol, sv);
if (ret < 0 && (errno == EMFILE || errno == ENFILE)) {
rb_gc();
ret = socketpair(domain, type, protocol, sv);
}
return ret;
}
/*
* call-seq:
* Socket.pair(domain, type, protocol) => [socket1, socket2]
@ -111,11 +126,7 @@ rsock_sock_s_socketpair(int argc, VALUE *argv, VALUE klass)
setup_domain_and_type(domain, &d, type, &t);
p = NUM2INT(protocol);
ret = socketpair(d, t, p, sp);
if (ret < 0 && (errno == EMFILE || errno == ENFILE)) {
rb_gc();
ret = socketpair(d, t, p, sp);
}
ret = rsock_socketpair(d, t, p, sp);
if (ret < 0) {
rb_sys_fail("socketpair(2)");
}