diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-12-05 02:37:07 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-12-05 02:37:07 +0000 |
commit | baa94e0239cfd0115b4a7de54c0aeab65375f743 (patch) | |
tree | e9d1a75ec61a3c30af53e424889529ffdae07c20 /win32 | |
parent | a2643fb4c457cf208c3625c831d6cab715059f03 (diff) |
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: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@26004 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r-- | win32/win32.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/win32/win32.c b/win32/win32.c index b461a78b03..e10fa89661 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 |