* io.c: avoid avoid data loss with nonblocking fd and

stdio buffering in sync mode.  [ruby-dev:24966]
  based on matz's patch [ruby-dev:24967]
  (io_fwrite): new primitive writing function which writes
  directly if sync mode.
  (rb_io_fwrite): wrapper for io_fwrite now.
  (io_write): call io_fwrite instead of rb_io_fwrite.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7392 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2004-11-27 13:05:46 +00:00
Родитель 2572d5e20e
Коммит b70e88a123
2 изменённых файлов: 57 добавлений и 17 удалений

Просмотреть файл

@ -1,3 +1,13 @@
Sat Nov 27 21:43:39 2004 Tanaka Akira <akr@m17n.org>
* io.c: avoid avoid data loss with nonblocking fd and
stdio buffering in sync mode. [ruby-dev:24966]
based on matz's patch [ruby-dev:24967]
(io_fwrite): new primitive writing function which writes
directly if sync mode.
(rb_io_fwrite): wrapper for io_fwrite now.
(io_write): call io_fwrite instead of rb_io_fwrite.
Sat Nov 27 17:43:21 2004 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/{0.9,1.0,2.0,trackback,xml-stylesheet}.rb: added
@ -27,7 +37,9 @@ Sat Nov 27 17:21:30 2004 Kouhei Sutou <kou@cozmixng.org>
Sat Nov 27 09:41:21 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (io_fread): [ruby-dev:24964]
* io.c (io_fread): old rb_io_fread with file closing checking.
(rb_io_fread): wrapper for io_fread now.
[ruby-dev:24964]
Fri Nov 26 18:02:44 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
@ -41,9 +53,10 @@ Fri Nov 26 18:02:44 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
Fri Nov 26 14:29:39 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_io_initialize): [ruby-dev:24963]
* io.c (rb_io_initialize): uninitialized fd was checked to see open
mode. [ruby-dev:24963]
* io.c (rb_io_initialize): [ruby-dev:24962]
* io.c (rb_io_initialize): uninitialized fd was used. [ruby-dev:24962]
Fri Nov 26 13:49:06 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
@ -53,7 +66,7 @@ Fri Nov 26 13:49:06 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (method_missing): raise TypeError for classes do not
have allocators. [ruby-core:03752]
* lib/erb.rb: [ruby-core:03786]
* lib/erb.rb: add RDoc by James Edward Gray II. [ruby-core:03786]
Fri Nov 26 13:29:02 2004 Dave Thomas <dave@pragprog.com>

53
io.c
Просмотреть файл

@ -398,14 +398,34 @@ rb_io_wait_writable(f)
/* writing functions */
long
rb_io_fwrite(ptr, len, f)
io_fwrite(ptr, len, fptr)
const char *ptr;
long len;
FILE *f;
OpenFile *fptr;
{
long n, r;
FILE *f = GetWriteFile(fptr);
if ((n = len) <= 0) return n;
if (fptr->mode & FMODE_SYNC) {
io_fflush(f, fptr);
if (!rb_thread_fd_writable(fileno(f))) {
rb_io_check_closed(fptr);
}
retry:
r = write(fileno(f), ptr, n);
if (r == n) return len;
if (0 <= r) {
ptr += r;
n -= r;
errno = EAGAIN;
}
if (rb_io_wait_writable(fileno(f))) {
rb_io_check_closed(fptr);
goto retry;
}
return -1L;
}
#if defined __human68k__
do {
if (fputc(*ptr++, f) == EOF) {
@ -424,6 +444,7 @@ rb_io_fwrite(ptr, len, f)
if (!errno) errno = EAGAIN;
#endif
if (rb_io_wait_writable(fileno(f))) {
rb_io_check_closed(fptr);
clearerr(f);
continue;
}
@ -434,6 +455,21 @@ rb_io_fwrite(ptr, len, f)
return len - n;
}
long
rb_io_fwrite(ptr, len, f)
const char *ptr;
long len;
FILE *f;
{
OpenFile of;
of.f = f;
of.f2 = NULL;
of.mode = FMODE_WRITABLE;
of.path = "(rb_io_fwrite)";
return io_fwrite(ptr, len, &of);
}
/*
* call-seq:
* ios.write(string) => integer
@ -457,7 +493,6 @@ io_write(io, str)
VALUE io, str;
{
OpenFile *fptr;
FILE *f;
long n;
VALUE tmp;
@ -473,16 +508,12 @@ io_write(io, str)
GetOpenFile(io, fptr);
rb_io_check_writable(fptr);
f = GetWriteFile(fptr);
rb_str_locktmp(str);
n = rb_io_fwrite(RSTRING(str)->ptr, RSTRING(str)->len, f);
n = io_fwrite(RSTRING(str)->ptr, RSTRING(str)->len, fptr);
rb_str_unlocktmp(str);
if (n == -1L) rb_sys_fail(fptr->path);
if (fptr->mode & FMODE_SYNC) {
io_fflush(f, fptr);
}
else {
if (!(fptr->mode & FMODE_SYNC)) {
fptr->mode |= FMODE_WBUF;
}
@ -1524,7 +1555,6 @@ rb_io_gets_m(argc, argv, io)
VALUE io;
{
VALUE rs, str;
OpenFile *fptr;
if (argc == 0) {
rs = rb_rs;
@ -1668,7 +1698,6 @@ rb_io_readlines(argc, argv, io)
{
VALUE line, ary;
VALUE rs;
OpenFile *fptr;
if (argc == 0) {
rs = rb_rs;
@ -1711,7 +1740,6 @@ rb_io_each_line(argc, argv, io)
VALUE io;
{
VALUE str;
OpenFile *fptr;
VALUE rs;
if (argc == 0) {
@ -5028,7 +5056,6 @@ rb_io_s_foreach(argc, argv)
VALUE *argv;
{
VALUE fname;
OpenFile *fptr;
struct foreach_arg arg;
rb_scan_args(argc, argv, "11", &fname, &arg.sep);