Skip to content

Commit bf98981

Browse files
committed
auto merge of #10270 : alexcrichton/rust/no-super-buffer, r=brson
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.
2 parents 1c56652 + 615444d commit bf98981

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/libstd/rt/io/stdio.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use fmt;
3030
use libc;
3131
use option::{Option, Some, None};
3232
use result::{Ok, Err};
33-
use rt::io::buffered::{LineBufferedWriter, BufferedWriter};
33+
use rt::io::buffered::LineBufferedWriter;
3434
use rt::rtio::{IoFactory, RtioTTY, RtioFileStream, with_local_io,
3535
CloseAsynchronously};
3636
use super::{Reader, Writer, io_error, IoError, OtherIoError};
@@ -135,14 +135,7 @@ fn with_task_stdout(f: &fn(&mut Writer)) {
135135
Some(ref mut handle) => f(*handle),
136136
None => {
137137
let handle = stdout();
138-
let mut handle = if handle.isatty() {
139-
~LineBufferedWriter::new(handle) as ~Writer
140-
} else {
141-
// The default capacity is very large, 64k, but this is just
142-
// a stdout stream, and possibly per task, so let's not make
143-
// this too expensive.
144-
~BufferedWriter::with_capacity(4096, handle) as ~Writer
145-
};
138+
let mut handle = ~LineBufferedWriter::new(handle) as ~Writer;
146139
f(handle);
147140
(*task).stdout_handle = Some(handle);
148141
}
@@ -152,10 +145,9 @@ fn with_task_stdout(f: &fn(&mut Writer)) {
152145

153146
/// Flushes the local task's stdout handle.
154147
///
155-
/// By default, this stream is a buffering stream, flushing may be necessary to
156-
/// ensure output is on the terminal screen. The buffering used is
157-
/// line-buffering when stdout is attached to a terminal, and a fixed sized
158-
/// buffer if it is not attached to a terminal.
148+
/// By default, this stream is a line-buffering stream, so flushing may be
149+
/// necessary to ensure that all output is printed to the screen (if there are
150+
/// no newlines printed).
159151
///
160152
/// Note that logging macros do not use this stream. Using the logging macros
161153
/// will emit output to stderr, and while they are line buffered the log

0 commit comments

Comments
 (0)