diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-01-06 14:17:23 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-01-06 16:32:51 -0800 |
| commit | 03e91573c73dbaa6afc905c6b14df4bb327589c9 (patch) | |
| tree | 5518b4e70db6ece31171438d7eb74ca4393d59bc /src/libstd | |
| parent | 3afa0b97c4ce81b3bbfd1e0dd4a6609742957678 (diff) | |
| download | rust-03e91573c73dbaa6afc905c6b14df4bb327589c9.tar.gz rust-03e91573c73dbaa6afc905c6b14df4bb327589c9.zip | |
Don't read forever on a file descriptor
Similarly to the recent commit to do this for networking, there's no reason that a read on a file descriptor should continue reading until the entire buffer is full. This makes sense when dealing with literal files, but when dealing with things like stdin this doesn't make sense.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/io/pipe.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libstd/io/pipe.rs b/src/libstd/io/pipe.rs index 2349c64a84b..e3f2cc2384c 100644 --- a/src/libstd/io/pipe.rs +++ b/src/libstd/io/pipe.rs @@ -80,3 +80,25 @@ impl Writer for PipeStream { } } } + +#[cfg(test)] +mod test { + iotest!(fn partial_read() { + use os; + use io::pipe::PipeStream; + + let os::Pipe { input, out } = os::pipe(); + let out = PipeStream::open(out); + let mut input = PipeStream::open(input); + let (p, c) = Chan::new(); + do spawn { + let mut out = out; + out.write([10]); + p.recv(); // don't close the pipe until the other read has finished + } + + let mut buf = [0, ..10]; + input.read(buf); + c.send(()); + }) +} |
