@@ -90,6 +90,12 @@ fn src<T>(fd: libc::c_int, readable: bool, f: |StdSource| -> T) -> T {
90
90
/// buffered access is not desired, the `stdin_raw` function is provided to
91
91
/// provided unbuffered access to stdin.
92
92
///
93
+ /// Care should be taken when creating multiple handles to the stdin of a
94
+ /// process. Beause this is a buffered reader by default, it's possible for
95
+ /// pending input to be unconsumed in one reader and unavailable to other
96
+ /// readers. It is recommended that only one handle at a time is created for the
97
+ /// stdin of a process.
98
+ ///
93
99
/// See `stdout()` for more notes about this function.
94
100
pub fn stdin ( ) -> BufferedReader < StdReader > {
95
101
BufferedReader :: new ( stdin_raw ( ) )
@@ -104,20 +110,38 @@ pub fn stdin_raw() -> StdReader {
104
110
src ( libc:: STDIN_FILENO , true , |src| StdReader { inner : src } )
105
111
}
106
112
107
- /// Creates a new non-blocking handle to the stdout of the current process.
113
+ /// Creates a line-buffered handle to the stdout of the current process.
108
114
///
109
115
/// Note that this is a fairly expensive operation in that at least one memory
110
116
/// allocation is performed. Additionally, this must be called from a runtime
111
117
/// task context because the stream returned will be a non-blocking object using
112
118
/// the local scheduler to perform the I/O.
113
- pub fn stdout ( ) -> StdWriter {
119
+ ///
120
+ /// Care should be taken when creating multiple handles to an output stream for
121
+ /// a single process. While usage is still safe, the output may be surprising if
122
+ /// no synchronization is performed to ensure a sane output.
123
+ pub fn stdout ( ) -> LineBufferedWriter < StdWriter > {
124
+ LineBufferedWriter :: new ( stdout_raw ( ) )
125
+ }
126
+
127
+ /// Creates an unbuffered handle to the stdout of the current process
128
+ ///
129
+ /// See notes in `stdout()` for more information.
130
+ pub fn stdout_raw ( ) -> StdWriter {
114
131
src ( libc:: STDOUT_FILENO , false , |src| StdWriter { inner : src } )
115
132
}
116
133
117
- /// Creates a new non-blocking handle to the stderr of the current process.
134
+ /// Creates a line-buffered handle to the stderr of the current process.
118
135
///
119
136
/// See `stdout()` for notes about this function.
120
- pub fn stderr ( ) -> StdWriter {
137
+ pub fn stderr ( ) -> LineBufferedWriter < StdWriter > {
138
+ LineBufferedWriter :: new ( stderr_raw ( ) )
139
+ }
140
+
141
+ /// Creates an unbuffered handle to the stderr of the current process
142
+ ///
143
+ /// See notes in `stdout()` for more information.
144
+ pub fn stderr_raw ( ) -> StdWriter {
121
145
src ( libc:: STDERR_FILENO , false , |src| StdWriter { inner : src } )
122
146
}
123
147
@@ -182,7 +206,7 @@ fn with_task_stdout(f: |&mut Writer| -> IoResult<()> ) {
182
206
Local :: put ( task) ;
183
207
184
208
if my_stdout. is_none ( ) {
185
- my_stdout = Some ( ~LineBufferedWriter :: new ( stdout ( ) ) as ~Writer ) ;
209
+ my_stdout = Some ( ~stdout ( ) as ~Writer ) ;
186
210
}
187
211
let ret = f ( * my_stdout. get_mut_ref ( ) ) ;
188
212
0 commit comments