summaryrefslogtreecommitdiff
path: root/ext/socket/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/socket/socket.c')
-rw-r--r--ext/socket/socket.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 767446d8da..31346a0295 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -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)");
}