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

ruby-changes:24892

From: kosaki <ko1@a...>
Date: Mon, 10 Sep 2012 02:29:32 +0900 (JST)
Subject: [ruby-changes:24892] kosaki:r36944 (trunk): * ext/socket/basicsocket.c (rsock_bsock_send):

kosaki	2012-09-10 02:29:12 +0900 (Mon, 10 Sep 2012)

  New Revision: 36944

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

  Log:
    * ext/socket/basicsocket.c (rsock_bsock_send):
      avoid unnecessary select() calls before doing I/O
      Patch by Eric Wong. [Feature #4538] [ruby-core:35586]
    * ext/socket/init.c (rsock_s_recvfrom): ditto.
    * ext/socket/init.c (rsock_s_accept): ditto.
    * ext/socket/udpsocket.c (udp_send): ditto.
    * io.c (io_fflush): ditto.
    * io.c (io_binwrite): ditto.
    * io.c (rb_io_syswrite): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/basicsocket.c
    trunk/ext/socket/init.c
    trunk/ext/socket/udpsocket.c
    trunk/io.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 36943)
+++ ChangeLog	(revision 36944)
@@ -1,3 +1,15 @@
+Sun Sep  9 22:02:50 2012  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* ext/socket/basicsocket.c (rsock_bsock_send):
+	  avoid unnecessary select() calls before doing I/O
+	  Patch by Eric Wong. [Feature #4538] [ruby-core:35586]
+	* ext/socket/init.c (rsock_s_recvfrom): ditto.
+	* ext/socket/init.c (rsock_s_accept): ditto.
+	* ext/socket/udpsocket.c (udp_send): ditto.
+	* io.c (io_fflush): ditto.
+	* io.c (io_binwrite): ditto.
+	* io.c (rb_io_syswrite): ditto.
+
 Mon Sep 10 01:38:51 2012  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* io.c (nogvl_close, maygvl_close, nogvl_fclose, maygvl_fclose):
Index: io.c
===================================================================
--- io.c	(revision 36943)
+++ io.c	(revision 36944)
@@ -975,9 +975,7 @@
     rb_io_check_closed(fptr);
     if (fptr->wbuf.len == 0)
         return 0;
-    if (!rb_thread_fd_writable(fptr->fd)) {
-        rb_io_check_closed(fptr);
-    }
+    rb_io_check_closed(fptr);
     while (fptr->wbuf.len > 0 && io_flush_buffer(fptr) != 0) {
 	if (!rb_io_wait_writable(fptr->fd))
 	    return -1;
@@ -1132,7 +1130,12 @@
         (fptr->wbuf.ptr && fptr->wbuf.capa <= fptr->wbuf.len + len)) {
 	struct binwrite_arg arg;
 
-        /* xxx: use writev to avoid double write if available */
+	/*
+	 * xxx: use writev to avoid double write if available
+	 * writev may help avoid context switch between "a" and "\n" in
+	 * STDERR.puts "a" [ruby-dev:25080] (rebroken since native threads
+	 * introduced in 1.9)
+	 */
         if (fptr->wbuf.len && fptr->wbuf.len+len <= fptr->wbuf.capa) {
             if (fptr->wbuf.capa < fptr->wbuf.off+fptr->wbuf.len+len) {
                 MEMMOVE(fptr->wbuf.ptr, fptr->wbuf.ptr+fptr->wbuf.off, char, fptr->wbuf.len);
@@ -1146,11 +1149,8 @@
             return -1L;
         if (n == 0)
             return len;
-        /* avoid context switch between "a" and "\n" in STDERR.puts "a".
-           [ruby-dev:25080] */
-	if (fptr->stdio_file != stderr && !rb_thread_fd_writable(fptr->fd)) {
-	    rb_io_check_closed(fptr);
-	}
+
+	rb_io_check_closed(fptr);
 	arg.fptr = fptr;
 	arg.str = str;
       retry:
@@ -4323,9 +4323,6 @@
     if (fptr->wbuf.len) {
 	rb_warn("syswrite for buffered IO");
     }
-    if (!rb_thread_fd_writable(fptr->fd)) {
-        rb_io_check_closed(fptr);
-    }
 
     n = rb_write_internal(fptr->fd, RSTRING_PTR(str), RSTRING_LEN(str));
 
Index: ext/socket/udpsocket.c
===================================================================
--- ext/socket/udpsocket.c	(revision 36943)
+++ ext/socket/udpsocket.c	(revision 36944)
@@ -176,7 +176,6 @@
       retry:
 	arg.to = res->ai_addr;
 	arg.tolen = res->ai_addrlen;
-	rb_thread_fd_writable(arg.fd);
 	n = (int)BLOCKING_REGION_FD(rsock_sendto_blocking, &arg);
 	if (n >= 0) {
 	    freeaddrinfo(res0);
Index: ext/socket/init.c
===================================================================
--- ext/socket/init.c	(revision 36943)
+++ ext/socket/init.c	(revision 36944)
@@ -130,7 +130,6 @@
     RBASIC(str)->klass = 0;
 
     while (rb_io_check_closed(fptr),
-	   rb_thread_wait_fd(arg.fd),
 	   (slen = BLOCKING_REGION_FD(recvfrom_blocking, &arg)) < 0) {
         if (!rb_io_wait_readable(fptr->fd)) {
             rb_sys_fail("recvfrom(2)");
@@ -560,7 +559,6 @@
     arg.sockaddr = sockaddr;
     arg.len = len;
   retry:
-    rb_thread_wait_fd(fd);
     fd2 = (int)BLOCKING_REGION_FD(accept_blocking, &arg);
     if (fd2 < 0) {
 	switch (errno) {
Index: ext/socket/basicsocket.c
===================================================================
--- ext/socket/basicsocket.c	(revision 36943)
+++ ext/socket/basicsocket.c	(revision 36944)
@@ -558,8 +558,7 @@
     GetOpenFile(sock, fptr);
     arg.fd = fptr->fd;
     arg.flags = NUM2INT(flags);
-    while (rb_thread_fd_writable(arg.fd),
-	   (n = (int)BLOCKING_REGION_FD(func, &arg)) < 0) {
+    while ((n = (int)BLOCKING_REGION_FD(func, &arg)) < 0) {
 	if (rb_io_wait_writable(arg.fd)) {
 	    continue;
 	}

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

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