From 84c77c15205d57a3d50d8b29bb6d2af2ff44de77 Mon Sep 17 00:00:00 2001 From: kosaki Date: Sun, 9 Sep 2012 17:29:12 +0000 Subject: * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 12 ++++++++++++ ext/socket/basicsocket.c | 3 +-- ext/socket/init.c | 2 -- ext/socket/udpsocket.c | 1 - io.c | 21 +++++++++------------ 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index c25a32cdef..fa30abb4e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Sun Sep 9 22:02:50 2012 KOSAKI Motohiro + + * 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 * io.c (nogvl_close, maygvl_close, nogvl_fclose, maygvl_fclose): diff --git a/ext/socket/basicsocket.c b/ext/socket/basicsocket.c index c1ae88d80c..84ea2bb6bd 100644 --- a/ext/socket/basicsocket.c +++ b/ext/socket/basicsocket.c @@ -558,8 +558,7 @@ rsock_bsock_send(int argc, VALUE *argv, VALUE sock) 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; } diff --git a/ext/socket/init.c b/ext/socket/init.c index 696b62d82a..3960a23300 100644 --- a/ext/socket/init.c +++ b/ext/socket/init.c @@ -130,7 +130,6 @@ rsock_s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from) 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 @@ rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len) 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) { diff --git a/ext/socket/udpsocket.c b/ext/socket/udpsocket.c index 0ba4371f1a..1b8756a904 100644 --- a/ext/socket/udpsocket.c +++ b/ext/socket/udpsocket.c @@ -176,7 +176,6 @@ udp_send(int argc, VALUE *argv, VALUE sock) 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); diff --git a/io.c b/io.c index 57f5775c41..24f141c825 100644 --- a/io.c +++ b/io.c @@ -975,9 +975,7 @@ io_fflush(rb_io_t *fptr) 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 @@ io_binwrite(VALUE str, const char *ptr, long len, rb_io_t *fptr, int nosync) (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 @@ io_binwrite(VALUE str, const char *ptr, long len, rb_io_t *fptr, int nosync) 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 @@ rb_io_syswrite(VALUE io, VALUE str) 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)); -- cgit v1.2.3