about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--ext/kgio/connect.c12
1 files 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);