diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-30 09:08:19 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-30 09:08:19 +0000 |
commit | 7a4a31064a59eba104d7204a320220a6cdbddf60 (patch) | |
tree | cc36ee673bf2f44a908ddb5ac64acb033444801b /win32 | |
parent | 374e2f34b12737fd2b8639b1633790be3b4ea568 (diff) | |
download | ruby-7a4a31064a59eba104d7204a320220a6cdbddf60.tar.gz |
* 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/trunk@21903 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 b948fe0d77..b248721915 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -4485,6 +4485,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)) @@ -4506,6 +4508,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)); @@ -4534,7 +4542,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) @@ -4582,9 +4590,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 |