diff options
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | io.c | 53 |
2 files changed, 54 insertions, 15 deletions
@@ -1,6 +1,18 @@ +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 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> @@ -17,7 +29,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> @@ -388,14 +388,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__) || defined(__vms) do { if (fputc(*ptr++, f) == EOF) { @@ -414,6 +434,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; } @@ -424,6 +445,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 @@ -447,7 +483,6 @@ io_write(io, str) VALUE io, str; { OpenFile *fptr; - FILE *f; long n; rb_secure(4); @@ -462,16 +497,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; } @@ -1390,7 +1421,6 @@ rb_io_gets_m(argc, argv, io) VALUE io; { VALUE rs, str; - OpenFile *fptr; if (argc == 0) { rs = rb_rs; @@ -1534,7 +1564,6 @@ rb_io_readlines(argc, argv, io) { VALUE line, ary; VALUE rs; - OpenFile *fptr; if (argc == 0) { rs = rb_rs; @@ -1577,7 +1606,6 @@ rb_io_each_line(argc, argv, io) VALUE io; { VALUE str; - OpenFile *fptr; VALUE rs; if (argc == 0) { @@ -4804,7 +4832,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); |