summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
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