mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
2276689595
commit
2b2b77d7a7
3 changed files with 38 additions and 2 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Mon Jul 18 09:36:25 2005 Tanaka Akira <akr@m17n.org>
|
||||||
|
|
||||||
|
* rubyio.h (FMODE_WSPLIT, FMODE_WSPLIT_INITIALIZED): new constant.
|
||||||
|
|
||||||
|
* io.c (wsplit_p): new function.
|
||||||
|
(io_fwrite): split writing data by PIPE_BUF if wsplit_p is true in
|
||||||
|
multi-threaded mode.
|
||||||
|
|
||||||
Sun Jul 17 13:46:54 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sun Jul 17 13:46:54 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* ext/io/wait/extconf.rb, ext/io/wait/wait.c: Win32 platforms support.
|
* ext/io/wait/extconf.rb, ext/io/wait/wait.c: Win32 platforms support.
|
||||||
|
|
30
io.c
30
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 */
|
/* writing functions */
|
||||||
static long
|
static long
|
||||||
io_fwrite(str, fptr)
|
io_fwrite(str, fptr)
|
||||||
VALUE str;
|
VALUE str;
|
||||||
OpenFile *fptr;
|
OpenFile *fptr;
|
||||||
{
|
{
|
||||||
long len, n, r, offset = 0;
|
long len, n, r, l, offset = 0;
|
||||||
FILE *f = GetWriteFile(fptr);
|
FILE *f = GetWriteFile(fptr);
|
||||||
|
|
||||||
len = RSTRING(str)->len;
|
len = RSTRING(str)->len;
|
||||||
|
@ -405,7 +424,14 @@ io_fwrite(str, fptr)
|
||||||
rb_io_check_closed(fptr);
|
rb_io_check_closed(fptr);
|
||||||
}
|
}
|
||||||
retry:
|
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 (r == n) return len;
|
||||||
if (0 <= r) {
|
if (0 <= r) {
|
||||||
offset += r;
|
offset += r;
|
||||||
|
|
2
rubyio.h
2
rubyio.h
|
@ -39,6 +39,8 @@ typedef struct OpenFile {
|
||||||
#define FMODE_SYNC 8
|
#define FMODE_SYNC 8
|
||||||
#define FMODE_WBUF 16
|
#define FMODE_WBUF 16
|
||||||
#define FMODE_RBUF 32
|
#define FMODE_RBUF 32
|
||||||
|
#define FMODE_WSPLIT 0x200
|
||||||
|
#define FMODE_WSPLIT_INITIALIZED 0x400
|
||||||
|
|
||||||
#define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
|
#define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue