mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
d0a84c2ce9
commit
cb07275001
3 changed files with 35 additions and 19 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Fri Jan 31 17:01:47 2014 Eric Wong <e@80x24.org>
|
||||||
|
|
||||||
|
* ext/socket/init.c (rsock_socket0): split out SOCK_CLOEXEC version
|
||||||
|
* ext/socket/socket.c (rsock_socketpair0): ditto
|
||||||
|
[ruby-core:60377]
|
||||||
|
|
||||||
Fri Jan 31 03:48:40 2014 Eric Wong <e@80x24.org>
|
Fri Jan 31 03:48:40 2014 Eric Wong <e@80x24.org>
|
||||||
|
|
||||||
* benchmark/driver: avoid large alloc in driver process
|
* benchmark/driver: avoid large alloc in driver process
|
||||||
|
|
|
@ -264,12 +264,11 @@ int rsock_detect_cloexec(int fd)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SOCK_CLOEXEC
|
||||||
static int
|
static int
|
||||||
rsock_socket0(int domain, int type, int proto)
|
rsock_socket0(int domain, int type, int proto)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#ifdef SOCK_CLOEXEC
|
|
||||||
static int cloexec_state = -1; /* <0: unknown, 0: ignored, >0: working */
|
static int cloexec_state = -1; /* <0: unknown, 0: ignored, >0: working */
|
||||||
|
|
||||||
if (cloexec_state > 0) { /* common path, if SOCK_CLOEXEC is defined */
|
if (cloexec_state > 0) { /* common path, if SOCK_CLOEXEC is defined */
|
||||||
|
@ -300,22 +299,28 @@ rsock_socket0(int domain, int type, int proto)
|
||||||
else { /* cloexec_state == 0 */
|
else { /* cloexec_state == 0 */
|
||||||
ret = socket(domain, type, proto);
|
ret = socket(domain, type, proto);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
ret = socket(domain, type, proto);
|
|
||||||
#endif
|
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
return -1;
|
return -1;
|
||||||
#ifdef SOCK_CLOEXEC
|
|
||||||
fix_cloexec:
|
fix_cloexec:
|
||||||
#endif
|
|
||||||
rb_maygvl_fd_fix_cloexec(ret);
|
rb_maygvl_fd_fix_cloexec(ret);
|
||||||
#ifdef SOCK_CLOEXEC
|
|
||||||
update_max_fd:
|
update_max_fd:
|
||||||
#endif
|
|
||||||
rb_update_max_fd(ret);
|
rb_update_max_fd(ret);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#else /* !SOCK_CLOEXEC */
|
||||||
|
static int
|
||||||
|
rsock_socket0(int domain, int type, int proto)
|
||||||
|
{
|
||||||
|
int ret = socket(domain, type, proto);
|
||||||
|
|
||||||
|
if (ret == -1)
|
||||||
|
return -1;
|
||||||
|
rb_fd_fix_cloexec(ret);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif /* !SOCK_CLOEXEC */
|
||||||
|
|
||||||
int
|
int
|
||||||
rsock_socket(int domain, int type, int proto)
|
rsock_socket(int domain, int type, int proto)
|
||||||
|
|
|
@ -168,12 +168,11 @@ pair_yield(VALUE pair)
|
||||||
|
|
||||||
#if defined HAVE_SOCKETPAIR
|
#if defined HAVE_SOCKETPAIR
|
||||||
|
|
||||||
|
#ifdef SOCK_CLOEXEC
|
||||||
static int
|
static int
|
||||||
rsock_socketpair0(int domain, int type, int protocol, int sv[2])
|
rsock_socketpair0(int domain, int type, int protocol, int sv[2])
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#ifdef SOCK_CLOEXEC
|
|
||||||
static int cloexec_state = -1; /* <0: unknown, 0: ignored, >0: working */
|
static int cloexec_state = -1; /* <0: unknown, 0: ignored, >0: working */
|
||||||
|
|
||||||
if (cloexec_state > 0) { /* common path, if SOCK_CLOEXEC is defined */
|
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 */
|
else { /* cloexec_state == 0 */
|
||||||
ret = socketpair(domain, type, protocol, sv);
|
ret = socketpair(domain, type, protocol, sv);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
ret = socketpair(domain, type, protocol, sv);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SOCK_CLOEXEC
|
|
||||||
fix_cloexec:
|
fix_cloexec:
|
||||||
#endif
|
|
||||||
rb_maygvl_fd_fix_cloexec(sv[0]);
|
rb_maygvl_fd_fix_cloexec(sv[0]);
|
||||||
rb_maygvl_fd_fix_cloexec(sv[1]);
|
rb_maygvl_fd_fix_cloexec(sv[1]);
|
||||||
|
|
||||||
#ifdef SOCK_CLOEXEC
|
|
||||||
update_max_fd:
|
update_max_fd:
|
||||||
#endif
|
|
||||||
rb_update_max_fd(sv[0]);
|
rb_update_max_fd(sv[0]);
|
||||||
rb_update_max_fd(sv[1]);
|
rb_update_max_fd(sv[1]);
|
||||||
|
|
||||||
return ret;
|
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
|
static int
|
||||||
rsock_socketpair(int domain, int type, int protocol, int sv[2])
|
rsock_socketpair(int domain, int type, int protocol, int sv[2])
|
||||||
|
|
Loading…
Add table
Reference in a new issue