mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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:
parent
2572d5e20e
commit
b70e88a123
2 changed files with 57 additions and 17 deletions
21
ChangeLog
21
ChangeLog
|
@ -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>
|
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
|
* 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>
|
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>
|
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>
|
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>
|
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
|
* eval.c (method_missing): raise TypeError for classes do not
|
||||||
have allocators. [ruby-core:03752]
|
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>
|
Fri Nov 26 13:29:02 2004 Dave Thomas <dave@pragprog.com>
|
||||||
|
|
||||||
|
|
53
io.c
53
io.c
|
@ -398,14 +398,34 @@ rb_io_wait_writable(f)
|
||||||
|
|
||||||
/* writing functions */
|
/* writing functions */
|
||||||
long
|
long
|
||||||
rb_io_fwrite(ptr, len, f)
|
io_fwrite(ptr, len, fptr)
|
||||||
const char *ptr;
|
const char *ptr;
|
||||||
long len;
|
long len;
|
||||||
FILE *f;
|
OpenFile *fptr;
|
||||||
{
|
{
|
||||||
long n, r;
|
long n, r;
|
||||||
|
FILE *f = GetWriteFile(fptr);
|
||||||
|
|
||||||
if ((n = len) <= 0) return n;
|
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__
|
#if defined __human68k__
|
||||||
do {
|
do {
|
||||||
if (fputc(*ptr++, f) == EOF) {
|
if (fputc(*ptr++, f) == EOF) {
|
||||||
|
@ -424,6 +444,7 @@ rb_io_fwrite(ptr, len, f)
|
||||||
if (!errno) errno = EAGAIN;
|
if (!errno) errno = EAGAIN;
|
||||||
#endif
|
#endif
|
||||||
if (rb_io_wait_writable(fileno(f))) {
|
if (rb_io_wait_writable(fileno(f))) {
|
||||||
|
rb_io_check_closed(fptr);
|
||||||
clearerr(f);
|
clearerr(f);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -434,6 +455,21 @@ rb_io_fwrite(ptr, len, f)
|
||||||
return len - n;
|
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:
|
* call-seq:
|
||||||
* ios.write(string) => integer
|
* ios.write(string) => integer
|
||||||
|
@ -457,7 +493,6 @@ io_write(io, str)
|
||||||
VALUE io, str;
|
VALUE io, str;
|
||||||
{
|
{
|
||||||
OpenFile *fptr;
|
OpenFile *fptr;
|
||||||
FILE *f;
|
|
||||||
long n;
|
long n;
|
||||||
VALUE tmp;
|
VALUE tmp;
|
||||||
|
|
||||||
|
@ -473,16 +508,12 @@ io_write(io, str)
|
||||||
|
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
rb_io_check_writable(fptr);
|
rb_io_check_writable(fptr);
|
||||||
f = GetWriteFile(fptr);
|
|
||||||
|
|
||||||
rb_str_locktmp(str);
|
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);
|
rb_str_unlocktmp(str);
|
||||||
if (n == -1L) rb_sys_fail(fptr->path);
|
if (n == -1L) rb_sys_fail(fptr->path);
|
||||||
if (fptr->mode & FMODE_SYNC) {
|
if (!(fptr->mode & FMODE_SYNC)) {
|
||||||
io_fflush(f, fptr);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fptr->mode |= FMODE_WBUF;
|
fptr->mode |= FMODE_WBUF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1524,7 +1555,6 @@ rb_io_gets_m(argc, argv, io)
|
||||||
VALUE io;
|
VALUE io;
|
||||||
{
|
{
|
||||||
VALUE rs, str;
|
VALUE rs, str;
|
||||||
OpenFile *fptr;
|
|
||||||
|
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
rs = rb_rs;
|
rs = rb_rs;
|
||||||
|
@ -1668,7 +1698,6 @@ rb_io_readlines(argc, argv, io)
|
||||||
{
|
{
|
||||||
VALUE line, ary;
|
VALUE line, ary;
|
||||||
VALUE rs;
|
VALUE rs;
|
||||||
OpenFile *fptr;
|
|
||||||
|
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
rs = rb_rs;
|
rs = rb_rs;
|
||||||
|
@ -1711,7 +1740,6 @@ rb_io_each_line(argc, argv, io)
|
||||||
VALUE io;
|
VALUE io;
|
||||||
{
|
{
|
||||||
VALUE str;
|
VALUE str;
|
||||||
OpenFile *fptr;
|
|
||||||
VALUE rs;
|
VALUE rs;
|
||||||
|
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
|
@ -5028,7 +5056,6 @@ rb_io_s_foreach(argc, argv)
|
||||||
VALUE *argv;
|
VALUE *argv;
|
||||||
{
|
{
|
||||||
VALUE fname;
|
VALUE fname;
|
||||||
OpenFile *fptr;
|
|
||||||
struct foreach_arg arg;
|
struct foreach_arg arg;
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "11", &fname, &arg.sep);
|
rb_scan_args(argc, argv, "11", &fname, &arg.sep);
|
||||||
|
|
Loading…
Add table
Reference in a new issue