[前][次][番号順一覧][スレッド一覧]

ruby-changes:15150

From: nobu <ko1@a...>
Date: Wed, 24 Mar 2010 14:35:30 +0900 (JST)
Subject: [ruby-changes:15150] Ruby:r27029 (trunk): * win32/win32.c (rb_w32_read): limit read size to 16KB if the file

nobu	2010-03-24 14:34:05 +0900 (Wed, 24 Mar 2010)

  New Revision: 27029

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27029

  Log:
    * win32/win32.c (rb_w32_read): limit read size to 16KB if the file
      seems to be console.  [ruby-core:28902]

  Modified files:
    trunk/ChangeLog
    trunk/win32/win32.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 27028)
+++ ChangeLog	(revision 27029)
@@ -1,3 +1,8 @@
+Wed Mar 24 14:33:56 2010  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* file.c (file_expand_path): set length of string before calling
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 27028)
+++ win32/win32.c	(revision 27029)
@@ -4835,6 +4835,8 @@
     DWORD read;
     DWORD wait;
     DWORD err;
+    size_t len;
+    size_t ret;
     OVERLAPPED ol, *pol = NULL;
 
     if (is_socket(sock))
@@ -4856,6 +4858,12 @@
 	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 @@
 	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 @@
 	}
     }
 
+    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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]