about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-04-07 01:11:31 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-04-08 00:03:12 -0700
commit6ac34926a4f704ecab09167f07b94aa269df5b98 (patch)
tree030910a0ace61dd622d10f0c27363f16b2a4d783 /src/libstd
parent00cbda2d0af81a054ba61bd237f98e033ba7a2fa (diff)
downloadrust-6ac34926a4f704ecab09167f07b94aa269df5b98.tar.gz
rust-6ac34926a4f704ecab09167f07b94aa269df5b98.zip
std: User a smaller stdin buffer on windows
Apparently windows doesn't like reading from stdin with a large buffer size, and
it also apparently is ok with a smaller buffer size. This changes the reader
returned by stdin() to return an 8k buffered reader for stdin rather than a 64k
buffered reader.

Apparently libuv has run into this before, taking a peek at their code, with a
specific comment in their console code saying that "ReadConsole can't handle big
buffers", which I presume is related to invoking ReadFile as if it were a file
descriptor.

Closes #13304
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/io/stdio.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs
index ae98333ca96..33306dba8de 100644
--- a/src/libstd/io/stdio.rs
+++ b/src/libstd/io/stdio.rs
@@ -99,7 +99,15 @@ fn src<T>(fd: libc::c_int, readable: bool, f: |StdSource| -> T) -> T {
 ///
 /// See `stdout()` for more notes about this function.
 pub fn stdin() -> BufferedReader<StdReader> {
-    BufferedReader::new(stdin_raw())
+    // The default buffer capacity is 64k, but apparently windows doesn't like
+    // 64k reads on stdin. See #13304 for details, but the idea is that on
+    // windows we use a slighly smaller buffer that's been seen to be
+    // acceptable.
+    if cfg!(windows) {
+        BufferedReader::with_capacity(8 * 1024, stdin_raw())
+    } else {
+        BufferedReader::new(stdin_raw())
+    }
 }
 
 /// Creates a new non-blocking handle to the stdin of the current process.