From 9ddd17b0e296eb279f05d418da6ad46319bcf0b5 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 12 Dec 2012 21:21:29 +0000 Subject: [PATCH] connect: split out my_socket() function This makes the retry logic for mismatched libc headers/kernel versions easier to understand and follow. --- ext/kgio/connect.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ext/kgio/connect.c b/ext/kgio/connect.c index ff5e639..783d6b4 100644 --- a/ext/kgio/connect.c +++ b/ext/kgio/connect.c @@ -26,8 +26,8 @@ static int MY_SOCK_STREAM = # define rb_fd_fix_cloexec(fd) for (;0;) #endif /* HAVE_RB_FD_FIX_CLOEXEC */ -static VALUE -my_connect(VALUE klass, int io_wait, int domain, void *addr, socklen_t addrlen) +/* try to use SOCK_NONBLOCK and SOCK_CLOEXEC */ +static int my_socket(int domain) { int fd; @@ -61,6 +61,14 @@ retry: rb_fd_fix_cloexec(fd); } + return fd; +} + +static VALUE +my_connect(VALUE klass, int io_wait, int domain, void *addr, socklen_t addrlen) +{ + int fd = my_socket(domain); + if (connect(fd, addr, addrlen) == -1) { if (errno == EINPROGRESS) { VALUE io = sock_for_fd(klass, fd); -- 2.11.4.GIT