diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-11-05 06:46:02 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-11-05 06:46:02 +0000 |
commit | 0e68c46e2dc4ae6603f9dd53a2048c6d8bddea10 (patch) | |
tree | ab1fb4d17cf350aed1630f39f348caa4a41cde10 /ext/socket | |
parent | d05202a5969404e24ff83a99a23ab5e19a54b374 (diff) | |
download | ruby-0e68c46e2dc4ae6603f9dd53a2048c6d8bddea10.tar.gz |
* ext/socket/init.c (rsock_socket0): extract single socket() call with
CLOEXEC handling from rsock_socket.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33637 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r-- | ext/socket/init.c | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/ext/socket/init.c b/ext/socket/init.c index 92cca7c057..b35226ab78 100644 --- a/ext/socket/init.c +++ b/ext/socket/init.c @@ -239,10 +239,10 @@ rsock_s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type return rb_assoc_new(str, addr); } -int -rsock_socket(int domain, int type0, int proto) +static int +rsock_socket0(int domain, int type0, int proto) { - int fd, type; + int ret, type; #ifdef SOCK_CLOEXEC static int try_sock_cloexec = 1; @@ -255,8 +255,9 @@ rsock_socket(int domain, int type0, int proto) type = type0; #endif - fd = socket(domain, type, proto); - if (fd < 0) { + ret = socket(domain, type, proto); + + if (ret == -1) { #ifdef SOCK_CLOEXEC /* SOCK_CLOEXEC is available since Linux 2.6.27. Linux 2.6.18 fails with EINVAL */ if (try_sock_cloexec && errno == EINVAL) { @@ -265,21 +266,29 @@ rsock_socket(int domain, int type0, int proto) goto retry_without_sock_cloexec; } #endif - if (errno == EMFILE || errno == ENFILE) { - rb_gc(); - fd = socket(domain, type, proto); - } + return -1; + } + + rb_fd_fix_cloexec(ret); + + return ret; + +} + +int +rsock_socket(int domain, int type, int proto) +{ + int fd; + + fd = rsock_socket0(domain, type, proto); + if (fd < 0) { + if (errno == EMFILE || errno == ENFILE) { + rb_gc(); + fd = rsock_socket0(domain, type, proto); + } } -#ifdef SOCK_CLOEXEC - if (0 <= fd) - if (try_sock_cloexec) - rb_update_max_fd(fd); - else - rb_fd_fix_cloexec(fd); -#else if (0 <= fd) - rb_fd_fix_cloexec(fd); -#endif + rb_update_max_fd(fd); return fd; } |