From a2e512ed8e5c2fe725f5b3a6313982948a86294d Mon Sep 17 00:00:00 2001 From: yugui Date: Sat, 5 Dec 2009 02:37:07 +0000 Subject: merges r21903 from trunk into ruby_1_9_1. fixes the backport task #1063. -- * win32/win32.c (rb_w32_write): limit write size to 32KB if the file seems to be console. [ruby-core:21613] git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@26004 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ version.h | 2 +- win32/win32.c | 19 +++++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4b25a82ba..e9837eea6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Jan 30 18:04:23 2009 NAKAMURA Usaku + + * win32/win32.c (rb_w32_write): limit write size to 32KB if the file + seems to be console. [ruby-core:21613] + Sat Oct 3 22:14:18 2009 Nobuyoshi Nakada * parse.y (bv_decls, bvar): fix for block variables. diff --git a/version.h b/version.h index 225831fdf..733f5ef18 100644 --- a/version.h +++ b/version.h @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.1" -#define RUBY_PATCHLEVEL 360 +#define RUBY_PATCHLEVEL 361 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 diff --git a/win32/win32.c b/win32/win32.c index b461a78b0..e10fa8966 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -4483,6 +4483,8 @@ rb_w32_write(int fd, const void *buf, size_t size) DWORD written; DWORD wait; DWORD err; + size_t len; + size_t ret; OVERLAPPED ol, *pol = NULL; if (is_socket(sock)) @@ -4504,6 +4506,12 @@ rb_w32_write(int fd, const void *buf, size_t size) return 0; } + ret = 0; + retry: + /* get rid of console writing bug */ + len = (_osfile(fd) & FDEV) ? min(32 * 1024, size) : size; + size -= len; + /* if have cancel_io, use Overlapped I/O */ if (cancel_io) { memset(&ol, 0, sizeof(ol)); @@ -4532,7 +4540,7 @@ rb_w32_write(int fd, const void *buf, size_t size) pol = &ol; } - if (!WriteFile((HANDLE)_osfhnd(fd), buf, size, &written, pol)) { + if (!WriteFile((HANDLE)_osfhnd(fd), buf, len, &written, pol)) { err = GetLastError(); if (err != ERROR_IO_PENDING) { if (err == ERROR_ACCESS_DENIED) @@ -4580,9 +4588,16 @@ rb_w32_write(int fd, const void *buf, size_t size) } } + ret += written; + if (written == len) { + (const char *)buf += len; + if (size > 0) + goto retry; + } + MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock)); - return written; + return ret; } static int -- cgit