summaryrefslogtreecommitdiff
path: root/ext/socket/init.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-05 08:56:50 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-05 08:56:50 +0000
commit385a7d4594da0168c7e9cf031f1e4a9c6ff46e8c (patch)
tree640afe34dda9501205efe84d9ce9f38e0651d0dd /ext/socket/init.c
parentc3749b6a6da86243ca16ed058216114e71c184f3 (diff)
* ext/socket/init.c (rsock_socket0): don't clear try_sock_cloexec if
SOCK_CLOEXEC is not a reason for EINVAL. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/init.c')
-rw-r--r--ext/socket/init.c36
1 files changed, 16 insertions, 20 deletions
diff --git a/ext/socket/init.c b/ext/socket/init.c
index b35226a..990f1a4 100644
--- a/ext/socket/init.c
+++ b/ext/socket/init.c
@@ -240,34 +240,30 @@ rsock_s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type
}
static int
-rsock_socket0(int domain, int type0, int proto)
+rsock_socket0(int domain, int type, int proto)
{
- int ret, type;
+ int ret;
#ifdef SOCK_CLOEXEC
static int try_sock_cloexec = 1;
- if (try_sock_cloexec)
- type = type0|SOCK_CLOEXEC;
- else
- type = type0;
- retry_without_sock_cloexec:;
+ if (try_sock_cloexec) {
+ ret = socket(domain, type|SOCK_CLOEXEC, proto);
+ if (ret == -1 && errno == EINVAL) {
+ /* SOCK_CLOEXEC is available since Linux 2.6.27. Linux 2.6.18 fails with EINVAL */
+ ret = socket(domain, type, proto);
+ if (ret != -1) {
+ try_sock_cloexec = 0;
+ }
+ }
+ }
+ else {
+ ret = socket(domain, type, proto);
+ }
#else
- type = type0;
-#endif
-
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) {
- try_sock_cloexec = 0;
- type = type0;
- goto retry_without_sock_cloexec;
- }
#endif
+ if (ret == -1)
return -1;
- }
rb_fd_fix_cloexec(ret);