summaryrefslogtreecommitdiff
path: root/ext/socket/socket.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-31 08:06:19 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-31 08:06:19 +0000
commitcb07275001f6e443dd909e1bd95f9a0ecdc8a4b0 (patch)
treed15fbae15001761dde6128eaca625df6a3a844ea /ext/socket/socket.c
parentd0a84c2ce9d984c99df59f0039c5bcee404df7b2 (diff)
socket: split out SOCK_CLOEXEC versions of wrappers for readability
* ext/socket/init.c (rsock_socket0): split out SOCK_CLOEXEC version * ext/socket/socket.c (rsock_socketpair0): ditto [ruby-core:60377] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/socket.c')
-rw-r--r--ext/socket/socket.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 31ac120c9d..d13b7e9dbc 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -168,12 +168,11 @@ pair_yield(VALUE pair)
#if defined HAVE_SOCKETPAIR
+#ifdef SOCK_CLOEXEC
static int
rsock_socketpair0(int domain, int type, int protocol, int sv[2])
{
int ret;
-
-#ifdef SOCK_CLOEXEC
static int cloexec_state = -1; /* <0: unknown, 0: ignored, >0: working */
if (cloexec_state > 0) { /* common path, if SOCK_CLOEXEC is defined */
@@ -206,28 +205,34 @@ rsock_socketpair0(int domain, int type, int protocol, int sv[2])
else { /* cloexec_state == 0 */
ret = socketpair(domain, type, protocol, sv);
}
-#else
- ret = socketpair(domain, type, protocol, sv);
-#endif
-
if (ret == -1) {
return -1;
}
-#ifdef SOCK_CLOEXEC
fix_cloexec:
-#endif
rb_maygvl_fd_fix_cloexec(sv[0]);
rb_maygvl_fd_fix_cloexec(sv[1]);
-#ifdef SOCK_CLOEXEC
update_max_fd:
-#endif
rb_update_max_fd(sv[0]);
rb_update_max_fd(sv[1]);
return ret;
}
+#else /* !SOCK_CLOEXEC */
+static int
+rsock_socketpair0(int domain, int type, int protocol, int sv[2])
+{
+ int ret = socketpair(domain, type, protocol, sv);
+
+ if (ret == -1)
+ return -1;
+
+ rb_fd_fix_cloexec(sv[0]);
+ rb_fd_fix_cloexec(sv[1]);
+ return ret;
+}
+#endif /* !SOCK_CLOEXEC */
static int
rsock_socketpair(int domain, int type, int protocol, int sv[2])