* 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
This commit is contained in:
nobu 2010-03-24 05:34:05 +00:00
Родитель 152934a300
Коммит cb2f56aaf4
2 изменённых файлов: 22 добавлений и 2 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Wed Mar 24 14:33:56 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/win32.c (rb_w32_read): limit read size to 16KB if the file
seems to be console. [ruby-core:28902]
Wed Mar 24 10:18:12 2010 NARUSE, Yui <naruse@ruby-lang.org>
* file.c (file_expand_path): set length of string before calling

Просмотреть файл

@ -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