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

ruby-changes:21549

From: akr <ko1@a...>
Date: Tue, 1 Nov 2011 12:04:21 +0900 (JST)
Subject: [ruby-changes:21549] akr:r33598 (trunk): * io.c (rb_maygvl_fd_fix_cloexec): renamed from fd_set_cloexec.

akr	2011-11-01 12:04:03 +0900 (Tue, 01 Nov 2011)

  New Revision: 33598

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

  Log:
    * io.c (rb_maygvl_fd_fix_cloexec): renamed from fd_set_cloexec.
    
    * internal.h (rb_maygvl_fd_fix_cloexec): declared.
    
    * ext/socket/init.c (cloexec_accept): use rb_maygvl_fd_fix_cloexec.
      (rsock_s_accept_nonblock): use rb_update_max_fd.
      (rsock_s_accept): use rb_update_max_fd.

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/init.c
    trunk/internal.h
    trunk/io.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33597)
+++ ChangeLog	(revision 33598)
@@ -1,3 +1,13 @@
+Tue Nov  1 12:00:53 2011  Tanaka Akira  <akr@f...>
+
+	* io.c (rb_maygvl_fd_fix_cloexec): renamed from fd_set_cloexec.
+
+	* internal.h (rb_maygvl_fd_fix_cloexec): declared.
+
+	* ext/socket/init.c (cloexec_accept): use rb_maygvl_fd_fix_cloexec.
+	  (rsock_s_accept_nonblock): use rb_update_max_fd.
+	  (rsock_s_accept): use rb_update_max_fd.
+
 Tue Nov  1 08:24:40 2011  Tanaka Akira  <akr@f...>
 
 	* ext/socket/init.c (cloexec_accept): new function to use accept4 if
Index: io.c
===================================================================
--- io.c	(revision 33597)
+++ io.c	(revision 33598)
@@ -157,15 +157,15 @@
     if (max_file_descriptor < fd) max_file_descriptor = fd;
 }
 
-static void
-fd_set_cloexec(int fd)
+void
+rb_maygvl_fd_fix_cloexec(int fd)
 {
   /* MinGW don't have F_GETFD and FD_CLOEXEC.  [ruby-core:40281] */
 #ifdef F_GETFD
     int flags, flags2, ret;
     flags = fcntl(fd, F_GETFD); /* should not fail except EBADF. */
     if (flags == -1) {
-        rb_bug("fd_set_cloexec: fcntl(%d, F_GETFD) failed: %s", fd, strerror(errno));
+        rb_bug("rb_maygvl_fd_fix_cloexec: fcntl(%d, F_GETFD) failed: %s", fd, strerror(errno));
     }
     if (fd <= 2)
         flags2 = flags & ~FD_CLOEXEC; /* Clear CLOEXEC for standard file descriptors: 0, 1, 2. */
@@ -174,7 +174,7 @@
     if (flags != flags2) {
         ret = fcntl(fd, F_SETFD, flags2);
         if (ret == -1) {
-            rb_bug("fd_set_cloexec: fcntl(%d, F_SETFD, %d) failed: %s", fd, flags2, strerror(errno));
+            rb_bug("rb_maygvl_fd_fix_cloexec: fcntl(%d, F_SETFD, %d) failed: %s", fd, flags2, strerror(errno));
         }
     }
 #endif
@@ -183,7 +183,7 @@
 void
 rb_fd_fix_cloexec(int fd)
 {
-    fd_set_cloexec(fd);
+    rb_maygvl_fd_fix_cloexec(fd);
     if (max_file_descriptor < fd) max_file_descriptor = fd;
 }
 
@@ -198,7 +198,7 @@
 #endif
     ret = open(pathname, flags, mode);
     if (ret == -1) return -1;
-    fd_set_cloexec(ret);
+    rb_maygvl_fd_fix_cloexec(ret);
     return ret;
 }
 
@@ -240,7 +240,7 @@
 #endif
         if (ret == -1) return -1;
     }
-    fd_set_cloexec(ret);
+    rb_maygvl_fd_fix_cloexec(ret);
     return ret;
 }
 
@@ -282,8 +282,8 @@
 	return -1;
     }
 #endif
-    fd_set_cloexec(fildes[0]);
-    fd_set_cloexec(fildes[1]);
+    rb_maygvl_fd_fix_cloexec(fildes[0]);
+    rb_maygvl_fd_fix_cloexec(fildes[1]);
     return ret;
 }
 
@@ -298,7 +298,7 @@
         ret = fcntl(fd, F_DUPFD_CLOEXEC, minfd);
         if (ret != -1) {
             if (ret <= 2)
-                fd_set_cloexec(ret);
+                rb_maygvl_fd_fix_cloexec(ret);
             return ret;
         }
         /* F_DUPFD_CLOEXEC is available since Linux 2.6.24.  Linux 2.6.18 fails with EINVAL */
@@ -314,7 +314,7 @@
     ret = fcntl(fd, F_DUPFD, minfd);
 #endif
     if (ret == -1) return -1;
-    fd_set_cloexec(ret);
+    rb_maygvl_fd_fix_cloexec(ret);
     return ret;
 }
 
Index: ext/socket/init.c
===================================================================
--- ext/socket/init.c	(revision 33597)
+++ ext/socket/init.c	(revision 33598)
@@ -472,7 +472,12 @@
     if (try_accept4) {
         ret = accept4(socket, address, address_len, SOCK_CLOEXEC);
         /* accept4 is available since Linux 2.6.28, glibc 2.10. */
-        if (ret == -1 && errno == ENOSYS) {
+        if (ret != -1) {
+            if (ret <= 2)
+                rb_maygvl_fd_fix_cloexec(ret);
+            return ret;
+        }
+        if (errno == ENOSYS) {
             try_accept4 = 0;
             ret = accept(socket, address, address_len);
         }
@@ -483,6 +488,8 @@
 #else
     ret = accept(socket, address, address_len);
 #endif
+    if (ret == -1) return -1;
+    rb_maygvl_fd_fix_cloexec(ret);
     return ret;
 }
 
@@ -509,7 +516,7 @@
 	}
         rb_sys_fail("accept(2)");
     }
-    rb_fd_fix_cloexec(fd2);
+    rb_update_max_fd(fd2);
     make_fd_nonblock(fd2);
     return rsock_init_sock(rb_obj_alloc(klass), fd2);
 }
@@ -556,7 +563,7 @@
 	}
 	rb_sys_fail(0);
     }
-    rb_fd_fix_cloexec(fd2);
+    rb_update_max_fd(fd2);
     if (!klass) return INT2NUM(fd2);
     return rsock_init_sock(rb_obj_alloc(klass), fd2);
 }
Index: internal.h
===================================================================
--- internal.h	(revision 33597)
+++ internal.h	(revision 33598)
@@ -102,6 +102,7 @@
 void ruby_set_inplace_mode(const char *);
 ssize_t rb_io_bufread(VALUE io, void *buf, size_t size);
 void rb_stdio_set_default_encoding(void);
+void rb_maygvl_fd_fix_cloexec(int fd);
 
 /* iseq.c */
 VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE filepath, VALUE line, VALUE opt);

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

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