about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-11-04 15:45:46 -0800
committerAlex Crichton <alex@alexcrichton.com>2013-11-04 15:48:34 -0800
commit615444d26306ddaf62388c73ae1dc17e48b3b2e3 (patch)
tree72784f8711c06637bafd38f93dcfdc23c6a5a423
parent658637baf45b41e4cff049440bc07f267d810218 (diff)
downloadrust-615444d26306ddaf62388c73ae1dc17e48b3b2e3.tar.gz
rust-615444d26306ddaf62388c73ae1dc17e48b3b2e3.zip
Stop extra buffering when stdout isn't a tty
Right now if you're running a program with its output piped to some location and
the program decides to go awry, when you kill the program via some signal none
of the program's last 4K of output will get printed to the screen. In theory the
solution to this would be to register a signal handler as part of the runtime
which then flushes the output stream.

I believe that the current behavior is far enough from what's expected that we
shouldn't be providing this sort of "super buffering" by default when stdout
isn't attached to a tty.
-rw-r--r--src/libstd/rt/io/stdio.rs18
1 files changed, 5 insertions, 13 deletions
diff --git a/src/libstd/rt/io/stdio.rs b/src/libstd/rt/io/stdio.rs
index fb1a3fac8d5..d33821a34b1 100644
--- a/src/libstd/rt/io/stdio.rs
+++ b/src/libstd/rt/io/stdio.rs
@@ -30,7 +30,7 @@ use fmt;
 use libc;
 use option::{Option, Some, None};
 use result::{Ok, Err};
-use rt::io::buffered::{LineBufferedWriter, BufferedWriter};
+use rt::io::buffered::LineBufferedWriter;
 use rt::rtio::{IoFactory, RtioTTY, RtioFileStream, with_local_io,
                CloseAsynchronously};
 use super::{Reader, Writer, io_error, IoError, OtherIoError};
@@ -135,14 +135,7 @@ fn with_task_stdout(f: &fn(&mut Writer)) {
             Some(ref mut handle) => f(*handle),
             None => {
                 let handle = stdout();
-                let mut handle = if handle.isatty() {
-                    ~LineBufferedWriter::new(handle) as ~Writer
-                } else {
-                    // The default capacity is very large, 64k, but this is just
-                    // a stdout stream, and possibly per task, so let's not make
-                    // this too expensive.
-                    ~BufferedWriter::with_capacity(4096, handle) as ~Writer
-                };
+                let mut handle = ~LineBufferedWriter::new(handle) as ~Writer;
                 f(handle);
                 (*task).stdout_handle = Some(handle);
             }
@@ -152,10 +145,9 @@ fn with_task_stdout(f: &fn(&mut Writer)) {
 
 /// Flushes the local task's stdout handle.
 ///
-/// By default, this stream is a buffering stream, flushing may be necessary to
-/// ensure output is on the terminal screen. The buffering used is
-/// line-buffering when stdout is attached to a terminal, and a fixed sized
-/// buffer if it is not attached to a terminal.
+/// By default, this stream is a line-buffering stream, so flushing may be
+/// necessary to ensure that all output is printed to the screen (if there are
+/// no newlines printed).
 ///
 /// Note that logging macros do not use this stream. Using the logging macros
 /// will emit output to stderr, and while they are line buffered the log