summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-24 05:34:05 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-24 05:34:05 +0000
commitcb2f56aaf48b24740fca6d24f0915d6b3cbb6db8 (patch)
tree28fc98f94ff7a1e3af411d57a5c1d658d70e69c5 /win32
parent152934a300d8becb43d7d260b8491d162cbd83ba (diff)
* win32/win32.c (rb_w32_read): limit read size to 16KB if the file
seems to be console. [ruby-core:28902] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 8216ac9918..58c24d4deb 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -4835,6 +4835,8 @@ rb_w32_read(int fd, void *buf, size_t size)
DWORD read;
DWORD wait;
DWORD err;
+ size_t len;
+ size_t ret;
OVERLAPPED ol, *pol = NULL;
if (is_socket(sock))
@@ -4856,6 +4858,12 @@ rb_w32_read(int fd, void *buf, size_t size)
return 0;
}
+ ret = 0;
+ retry:
+ /* get rid of console writing bug */
+ len = (_osfile(fd) & FDEV) ? min(16 * 1024, size) : size;
+ size -= len;
+
/* if have cancel_io, use Overlapped I/O */
if (cancel_io) {
memset(&ol, 0, sizeof(ol));
@@ -4884,7 +4892,7 @@ rb_w32_read(int fd, void *buf, size_t size)
pol = &ol;
}
- if (!ReadFile((HANDLE)_osfhnd(fd), buf, size, &read, pol)) {
+ if (!ReadFile((HANDLE)_osfhnd(fd), buf, len, &read, pol)) {
err = GetLastError();
if (err != ERROR_IO_PENDING) {
if (err == ERROR_ACCESS_DENIED)
@@ -4940,9 +4948,16 @@ rb_w32_read(int fd, void *buf, size_t size)
}
}
+ ret += read;
+ if (read == len) {
+ buf = (char *)buf + len;
+ if (size > 0)
+ goto retry;
+ }
+
MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock));
- return read;
+ return ret;
}
#undef write