summaryrefslogtreecommitdiff
path: root/ext/socket
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-01 03:04:03 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-01 03:04:03 +0000
commitc16f98ab0a4976998d7ff35ffbbb4f3ca110439b (patch)
treec6ee1f7f1f70bff58c09d2842326b39ec64b6bdb /ext/socket
parent632f448827347626d0c8d1ceef234b00984ce7a4 (diff)
* io.c (rb_maygvl_fd_fix_cloexec): renamed from fd_set_cloexec.
* internal.h (rb_maygvl_fd_fix_cloexec): declared. * ext/socket/init.c (cloexec_accept): use rb_maygvl_fd_fix_cloexec. (rsock_s_accept_nonblock): use rb_update_max_fd. (rsock_s_accept): use rb_update_max_fd. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r--ext/socket/init.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/ext/socket/init.c b/ext/socket/init.c
index a41f94a..ad25ccb 100644
--- a/ext/socket/init.c
+++ b/ext/socket/init.c
@@ -472,7 +472,12 @@ cloexec_accept(int socket, struct sockaddr *address, socklen_t *address_len)
if (try_accept4) {
ret = accept4(socket, address, address_len, SOCK_CLOEXEC);
/* accept4 is available since Linux 2.6.28, glibc 2.10. */
- if (ret == -1 && errno == ENOSYS) {
+ if (ret != -1) {
+ if (ret <= 2)
+ rb_maygvl_fd_fix_cloexec(ret);
+ return ret;
+ }
+ if (errno == ENOSYS) {
try_accept4 = 0;
ret = accept(socket, address, address_len);
}
@@ -483,6 +488,8 @@ cloexec_accept(int socket, struct sockaddr *address, socklen_t *address_len)
#else
ret = accept(socket, address, address_len);
#endif
+ if (ret == -1) return -1;
+ rb_maygvl_fd_fix_cloexec(ret);
return ret;
}
@@ -509,7 +516,7 @@ rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, s
}
rb_sys_fail("accept(2)");
}
- rb_fd_fix_cloexec(fd2);
+ rb_update_max_fd(fd2);
make_fd_nonblock(fd2);
return rsock_init_sock(rb_obj_alloc(klass), fd2);
}
@@ -556,7 +563,7 @@ rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
}
rb_sys_fail(0);
}
- rb_fd_fix_cloexec(fd2);
+ rb_update_max_fd(fd2);
if (!klass) return INT2NUM(fd2);
return rsock_init_sock(rb_obj_alloc(klass), fd2);
}