зеркало из https://github.com/github/ruby.git
* 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
This commit is contained in:
Родитель
946f7fc788
Коммит
84c77c1520
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
Sun Sep 9 22:02:50 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||
|
||||
* 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@gmail.com>
|
||||
|
||||
* io.c (nogvl_close, maygvl_close, nogvl_fclose, maygvl_fclose):
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
21
io.c
21
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));
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче