[前][次][番号順一覧][スレッド一覧]

ruby-changes:21588

From: akr <ko1@a...>
Date: Sat, 5 Nov 2011 15:46:14 +0900 (JST)
Subject: [ruby-changes:21588] akr:r33637 (trunk): * ext/socket/init.c (rsock_socket0): extract single socket() call with

akr	2011-11-05 15:46:02 +0900 (Sat, 05 Nov 2011)

  New Revision: 33637

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33637

  Log:
    * ext/socket/init.c (rsock_socket0): extract single socket() call with
      CLOEXEC handling from rsock_socket.

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/init.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33636)
+++ ChangeLog	(revision 33637)
@@ -1,3 +1,8 @@
+Sat Nov  5 15:45:04 2011  Tanaka Akira  <akr@f...>
+
+	* ext/socket/init.c (rsock_socket0): extract single socket() call with
+	  CLOEXEC handling from rsock_socket.
+
 Sat Nov  5 11:18:12 2011  Tanaka Akira  <akr@f...>
 
 	* ext/socket/socket.c (rsock_socketpair0): don't clear
Index: ext/socket/init.c
===================================================================
--- ext/socket/init.c	(revision 33636)
+++ ext/socket/init.c	(revision 33637)
@@ -239,10 +239,10 @@
     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 @@
     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 @@
             goto retry_without_sock_cloexec;
         }
 #endif
-	if (errno == EMFILE || errno == ENFILE) {
-	    rb_gc();
-	    fd = socket(domain, type, proto);
-	}
+        return -1;
     }
-#ifdef SOCK_CLOEXEC
+
+    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);
+       }
+    }
     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;
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]