summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-07-18 01:00:23 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-07-18 01:00:23 +0000
commit2b2b77d7a7afc91773324d0cde1c81a746b5baf1 (patch)
treed023c094a62f86757a19c0243670661f63146bd4 /io.c
parent227668959539a269b4a8186b1fdb92a5716bf6d3 (diff)
* 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/branches/ruby_1_8@8787 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/io.c b/io.c
index 8eb8437..c94109e 100644
--- a/io.c
+++ b/io.c
@@ -388,13 +388,32 @@ rb_io_wait_writable(f)
}
}
+static int
+wsplit_p(OpenFile *fptr)
+{
+ FILE *f = GetWriteFile(fptr);
+ int r;
+ if (!(fptr->mode & FMODE_WSPLIT_INITIALIZED)) {
+ struct stat buf;
+ if (fstat(fileno(f), &buf) == 0 &&
+ !(S_ISREG(buf.st_mode) ||
+ S_ISDIR(buf.st_mode)) &&
+ (r = fcntl(fileno(f), F_GETFL)) != -1 &&
+ !(r & O_NONBLOCK)) {
+ fptr->mode |= FMODE_WSPLIT;
+ }
+ fptr->mode |= FMODE_WSPLIT_INITIALIZED;
+ }
+ return fptr->mode & FMODE_WSPLIT;
+}
+
/* writing functions */
static long
io_fwrite(str, fptr)
VALUE str;
OpenFile *fptr;
{
- long len, n, r, offset = 0;
+ long len, n, r, l, offset = 0;
FILE *f = GetWriteFile(fptr);
len = RSTRING(str)->len;
@@ -405,7 +424,14 @@ io_fwrite(str, fptr)
rb_io_check_closed(fptr);
}
retry:
- r = write(fileno(f), RSTRING(str)->ptr+offset, n);
+ l = n;
+ if (PIPE_BUF < l &&
+ !rb_thread_critical &&
+ !rb_thread_alone() &&
+ wsplit_p(fptr)) {
+ l = PIPE_BUF;
+ }
+ r = write(fileno(f), RSTRING(str)->ptr+offset, l);
if (r == n) return len;
if (0 <= r) {
offset += r;