Project

General

Profile

Feature #4538 ยป 0001-avoid-unnecessary-select-calls-before-doing-I-O.patch

patch to remove unnecessary select() calls - normalperson (Eric Wong), 03/30/2011 03:22 AM

View differences:

ext/socket/basicsocket.c
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;
}
ext/socket/init.c
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)");
......
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) {
ext/socket/udpsocket.c
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);
io.c
rb_io_check_closed(fptr);
if (fptr->wbuf.len == 0)
return 0;
if (!rb_thread_fd_writable(fptr->fd)) {
rb_io_check_closed(fptr);
}
while (fptr->wbuf.len > 0 && io_flush_buffer(fptr) != 0) {
if (!rb_io_wait_writable(fptr->fd))
return -1;
......
(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);
......
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:
......
}
offset += c;
if ((n -= c) <= 0) break;
rb_thread_wait_fd(fptr->fd);
}
return len - n;
}
......
offset += c;
if ((n -= c) <= 0) break;
}
rb_thread_wait_fd(fptr->fd);
rb_io_check_closed(fptr);
if (io_fillbuf(fptr) < 0) {
break;
......
if (fptr->wbuf.len) {
rb_warn("syswrite for buffered IO");
}
if (!rb_thread_fd_writable(fptr->fd)) {
rb_io_check_closed(fptr);
}
n = write(fptr->fd, RSTRING_PTR(str), RSTRING_LEN(str));
......
}
n = fptr->fd;
rb_thread_wait_fd(fptr->fd);
rb_io_check_closed(fptr);
rb_str_locktmp(str);
......
}
else {
ssize_t ss;
rb_thread_wait_fd(stp->src_fd);
rb_str_resize(buf, buflen);
ss = maygvl_copy_stream_read(stp, RSTRING_PTR(buf), l, off);
if (ss == -1)
    (1-1/1)