diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-01-28 14:37:34 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-01-28 14:37:34 +0000 |
commit | 965b947fff6453464acfc9726db09db359db920b (patch) | |
tree | 431763219edb8e8be63cf5f7978e90acff0e604e /ext/socket/ancdata.c | |
parent | fbf4850cabbb7dc50be08660fe39889d03a03b96 (diff) |
* ext/socket: Avoid redundant fcntl/fstat syscalls for cloexec
sockets.
Patch by Eric Wong. [ruby-core:59429] [Feature #9330]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/ancdata.c')
-rw-r--r-- | ext/socket/ancdata.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c index 9a68a0c289..7054d654ea 100644 --- a/ext/socket/ancdata.c +++ b/ext/socket/ancdata.c @@ -2,6 +2,8 @@ #include <time.h> +int rsock_cmsg_cloexec_state = -1; /* <0: unknown, 0: ignored, >0: working */ + #if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL) static VALUE rb_cAncillaryData; @@ -1416,7 +1418,7 @@ discard_cmsg(struct cmsghdr *cmh, char *msg_end, int msg_peek_p) int *end = (int *)((char *)cmh + cmh->cmsg_len); while ((char *)fdp + sizeof(int) <= (char *)end && (char *)fdp + sizeof(int) <= msg_end) { - rb_fd_fix_cloexec(*fdp); + rb_update_max_fd(*fdp); close(*fdp); fdp++; } @@ -1459,7 +1461,11 @@ make_io_for_unix_rights(VALUE ctl, struct cmsghdr *cmh, char *msg_end) VALUE io; if (fstat(fd, &stbuf) == -1) rb_raise(rb_eSocket, "invalid fd in SCM_RIGHTS"); - rb_fd_fix_cloexec(fd); + rb_update_max_fd(fd); + if (rsock_cmsg_cloexec_state < 0) + rsock_cmsg_cloexec_state = rsock_detect_cloexec(fd); + if (rsock_cmsg_cloexec_state == 0 || fd <= 2) + rb_maygvl_fd_fix_cloexec(fd); if (S_ISSOCK(stbuf.st_mode)) io = rsock_init_sock(rb_obj_alloc(rb_cSocket), fd); else |