diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-07-18 01:00:23 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-07-18 01:00:23 +0000 |
commit | 8c2e1ce91cfd5561028d54e537c8173971f33338 (patch) | |
tree | d602619c9baea7bba562a542d8854168ee862663 /io.c | |
parent | c065b233c6020e9a63e5f941f8254d7f8d2d0c8a (diff) | |
download | ruby-8c2e1ce91cfd5561028d54e537c8173971f33338.tar.gz |
* rubyio.h (FMODE_WSPLIT, FMODE_WSPLIT_INITIALIZED): new constant.
* io.c (wsplit_p): new function.
(io_fflush): split writing data by PIPE_BUF if wsplit_p is true in
multi-threaded mode.
(io_fwrite): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8787 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 40 |
1 files changed, 36 insertions, 4 deletions
@@ -373,10 +373,28 @@ io_alloc(klass) } static int +wsplit_p(OpenFile *fptr) +{ + int r; + if (!(fptr->mode & FMODE_WSPLIT_INITIALIZED)) { + struct stat buf; + if (fstat(fptr->fd, &buf) == 0 && + !(S_ISREG(buf.st_mode) || + S_ISDIR(buf.st_mode)) && + (r = fcntl(fptr->fd, F_GETFL)) != -1 && + !(r & O_NONBLOCK)) { + fptr->mode |= FMODE_WSPLIT; + } + fptr->mode |= FMODE_WSPLIT_INITIALIZED; + } + return fptr->mode & FMODE_WSPLIT; +} + +static int io_fflush(fptr) OpenFile *fptr; { - int r; + int r, l; int wbuf_off, wbuf_len; rb_io_check_closed(fptr); @@ -390,8 +408,15 @@ io_fflush(fptr) return 0; wbuf_off = fptr->wbuf_off; wbuf_len = fptr->wbuf_len; + l = fptr->wbuf_len; + if (PIPE_BUF < l && + !rb_thread_critical && + !rb_thread_alone() && + wsplit_p(fptr)) { + l = PIPE_BUF; + } TRAP_BEG; - r = write(fptr->fd, fptr->wbuf+fptr->wbuf_off, fptr->wbuf_len); + r = write(fptr->fd, fptr->wbuf+fptr->wbuf_off, l); TRAP_END; /* xxx: signal handler may modify wbuf */ if (r == fptr->wbuf_len) { fptr->wbuf_off = 0; @@ -504,7 +529,7 @@ io_fwrite(str, fptr) VALUE str; OpenFile *fptr; { - long len, n, r, offset = 0; + long len, n, r, l, offset = 0; len = RSTRING(str)->len; if ((n = len) <= 0) return n; @@ -537,8 +562,15 @@ io_fwrite(str, fptr) rb_io_check_closed(fptr); } retry: + l = n; + if (PIPE_BUF < l && + !rb_thread_critical && + !rb_thread_alone() && + wsplit_p(fptr)) { + l = PIPE_BUF; + } TRAP_BEG; - r = write(fptr->fd, RSTRING(str)->ptr+offset, n); + r = write(fptr->fd, RSTRING(str)->ptr+offset, l); TRAP_END; /* xxx: signal handler may modify given string. */ if (r == n) return len; if (0 <= r) { |