The general idea is to remove conditions completely from I/O, so in the meantime
remove the read_error condition to mean the same thing as the io_error condition.
use iter::Iterator;
use vec;
use rt::io::{Reader, Writer, Decorator};
-use rt::io::{read_error, standard_error, EndOfFile, DEFAULT_BUF_SIZE};
+use rt::io::{io_error, standard_error, EndOfFile, DEFAULT_BUF_SIZE};
use option::{Option, Some, None};
use unstable::finally::Finally;
use cast;
///
/// # Failure
///
- /// Raises the same conditions as `read`. Additionally raises `read_error`
- /// on EOF. If `read_error` is handled then `push_bytes` may push less
+ /// Raises the same conditions as `read`. Additionally raises `io_error`
+ /// on EOF. If `io_error` is handled then `push_bytes` may push less
/// than the requested number of bytes.
fn push_bytes(&mut self, buf: &mut ~[u8], len: uint);
///
/// # Failure
///
- /// Raises the same conditions as `read`. Additionally raises `read_error`
- /// on EOF. If `read_error` is handled then the returned vector may
+ /// Raises the same conditions as `read`. Additionally raises `io_error`
+ /// on EOF. If `io_error` is handled then the returned vector may
/// contain less than the requested number of bytes.
fn read_bytes(&mut self, len: uint) -> ~[u8];
total_read += nread;
}
None => {
- read_error::cond.raise(standard_error(EndOfFile));
+ io_error::cond.raise(standard_error(EndOfFile));
break;
}
}
fn read_to_end(&mut self) -> ~[u8] {
let mut buf = vec::with_capacity(DEFAULT_BUF_SIZE);
let mut keep_reading = true;
- do read_error::cond.trap(|e| {
+ do io_error::cond.trap(|e| {
if e.kind == EndOfFile {
keep_reading = false;
} else {
- read_error::cond.raise(e)
+ io_error::cond.raise(e)
}
}).inside {
while keep_reading {
use cell::Cell;
use rt::io::mem::{MemReader, MemWriter};
use rt::io::mock::MockReader;
- use rt::io::{read_error, placeholder_error};
+ use rt::io::{io_error, placeholder_error};
#[test]
fn read_byte() {
fn read_byte_error() {
let mut reader = MockReader::new();
reader.read = |_| {
- read_error::cond.raise(placeholder_error());
+ io_error::cond.raise(placeholder_error());
None
};
- do read_error::cond.trap(|_| {
+ do io_error::cond.trap(|_| {
}).inside {
let byte = reader.read_byte();
assert!(byte == None);
fn bytes_error() {
let mut reader = MockReader::new();
reader.read = |_| {
- read_error::cond.raise(placeholder_error());
+ io_error::cond.raise(placeholder_error());
None
};
let mut it = reader.bytes();
- do read_error::cond.trap(|_| ()).inside {
+ do io_error::cond.trap(|_| ()).inside {
let byte = it.next();
assert!(byte == None);
}
#[test]
fn read_bytes_eof() {
let mut reader = MemReader::new(~[10, 11]);
- do read_error::cond.trap(|_| {
+ do io_error::cond.trap(|_| {
}).inside {
assert!(reader.read_bytes(4) == ~[10, 11]);
}
fn push_bytes_eof() {
let mut reader = MemReader::new(~[10, 11]);
let mut buf = ~[8, 9];
- do read_error::cond.trap(|_| {
+ do io_error::cond.trap(|_| {
}).inside {
reader.push_bytes(&mut buf, 4);
assert!(buf == ~[8, 9, 10, 11]);
buf[0] = 10;
Some(1)
} else {
- read_error::cond.raise(placeholder_error());
+ io_error::cond.raise(placeholder_error());
None
}
}
};
let mut buf = ~[8, 9];
- do read_error::cond.trap(|_| { } ).inside {
+ do io_error::cond.trap(|_| { } ).inside {
reader.push_bytes(&mut buf, 4);
}
assert!(buf == ~[8, 9, 10]);
buf[0] = 10;
Some(1)
} else {
- read_error::cond.raise(placeholder_error());
+ io_error::cond.raise(placeholder_error());
None
}
}
buf[1] = 11;
Some(2)
} else {
- read_error::cond.raise(placeholder_error());
+ io_error::cond.raise(placeholder_error());
None
}
}
objects such as strings and `Path` instances.
All operations in this module, including those as part of `FileStream` et al
-block the task during execution. Most will raise `std::rt::io::{io_error,read_error}`
+block the task during execution. Most will raise `std::rt::io::{io_error,io_error}`
conditions in the event of failure.
Also included in this module are the `FileInfo` and `DirectoryInfo` traits. When
use super::{Reader, Writer, Seek};
use super::{SeekStyle, Read, Write};
use rt::rtio::{RtioFileStream, IoFactory, with_local_io};
-use rt::io::{io_error, read_error, EndOfFile,
+use rt::io::{io_error, EndOfFile,
FileMode, FileAccess, FileStat, IoError,
PathAlreadyExists, PathDoesntExist,
MismatchedFileTypeForOperation, ignore_io_error};
Err(ioerr) => {
// EOF is indicated by returning None
if ioerr.kind != EndOfFile {
- read_error::cond.raise(ioerr);
+ io_error::cond.raise(ioerr);
}
return None;
}
match self.fd.flush() {
Ok(_) => (),
Err(ioerr) => {
- read_error::cond.raise(ioerr);
+ io_error::cond.raise(ioerr);
}
}
}
match res {
Ok(cursor) => cursor,
Err(ioerr) => {
- read_error::cond.raise(ioerr);
+ io_error::cond.raise(ioerr);
return -1;
}
}
()
},
Err(ioerr) => {
- read_error::cond.raise(ioerr);
+ io_error::cond.raise(ioerr);
}
}
}
pub io_error: IoError -> ();
}
-// XXX: Can't put doc comments on macros
-// Raised by `read` on error
-condition! {
- pub read_error: IoError -> ();
-}
-
/// Helper for wrapper calls where you want to
/// ignore any io_errors that might be raised
pub fn ignore_io_error<T>(cb: &fn() -> T) -> T {
///
/// # Failure
///
- /// Raises the `read_error` condition on error. If the condition
+ /// Raises the `io_error` condition on error. If the condition
/// is handled then no guarantee is made about the number of bytes
/// read and the contents of `buf`. If the condition is handled
/// returns `None` (XXX see below).
use result::{Ok, Err};
use rt::io::net::ip::SocketAddr;
use rt::io::{Reader, Writer, Listener, Acceptor};
-use rt::io::{io_error, read_error, EndOfFile};
+use rt::io::{io_error, EndOfFile};
use rt::rtio::{IoFactory, with_local_io,
RtioSocket, RtioTcpListener, RtioTcpAcceptor, RtioTcpStream};
Err(ioerr) => {
// EOF is indicated by returning None
if ioerr.kind != EndOfFile {
- read_error::cond.raise(ioerr);
+ io_error::cond.raise(ioerr);
}
return None;
}
let mut buf = [0];
let nread = stream.read(buf);
assert!(nread.is_none());
- do read_error::cond.trap(|e| {
+ do io_error::cond.trap(|e| {
if cfg!(windows) {
assert_eq!(e.kind, NotConnected);
} else {
let mut buf = [0];
let nread = stream.read(buf);
assert!(nread.is_none());
- do read_error::cond.trap(|e| {
+ do io_error::cond.trap(|e| {
if cfg!(windows) {
assert_eq!(e.kind, NotConnected);
} else {
use result::{Ok, Err};
use rt::io::net::ip::SocketAddr;
use rt::io::{Reader, Writer};
-use rt::io::{io_error, read_error, EndOfFile};
+use rt::io::{io_error, EndOfFile};
use rt::rtio::{RtioSocket, RtioUdpSocket, IoFactory, with_local_io};
pub struct UdpSocket {
Err(ioerr) => {
// EOF is indicated by returning None
if ioerr.kind != EndOfFile {
- read_error::cond.raise(ioerr);
+ io_error::cond.raise(ioerr);
}
None
}
use option::*;
use super::{Reader, Writer, Listener, Acceptor, Seek, SeekStyle};
-use super::{standard_error, PreviousIoError, io_error, read_error, IoError};
+use super::{standard_error, PreviousIoError, io_error, IoError};
fn prev_io_error() -> IoError {
standard_error(PreviousIoError)
match *self {
Some(ref mut reader) => reader.read(buf),
None => {
- read_error::cond.raise(prev_io_error());
+ io_error::cond.raise(prev_io_error());
None
}
}
use option::*;
use super::super::mem::*;
use rt::test::*;
- use super::super::{PreviousIoError, io_error, read_error};
+ use super::super::{PreviousIoError, io_error, io_error};
#[test]
fn test_option_writer() {
let mut buf = [];
let mut called = false;
- do read_error::cond.trap(|err| {
+ do io_error::cond.trap(|err| {
assert_eq!(err.kind, PreviousIoError);
called = true;
}).inside {
use prelude::*;
use super::{Reader, Writer};
-use rt::io::{io_error, read_error, EndOfFile};
+use rt::io::{io_error, EndOfFile};
use rt::rtio::RtioPipe;
pub struct PipeStream {
Err(ioerr) => {
// EOF is indicated by returning None
if ioerr.kind != EndOfFile {
- read_error::cond.raise(ioerr);
+ io_error::cond.raise(ioerr);
}
return None;
}
let file = get_single_str_from_tts(cx, sp, tts, "include_str!");
let file = res_rel_file(cx, sp, &Path::new(file));
let mut error = None;
- let bytes = do io::read_error::cond.trap(|e| error = Some(e)).inside {
+ let bytes = do io::io_error::cond.trap(|e| error = Some(e)).inside {
file.open_reader(io::Open).read_to_end()
};
match error {
let file = res_rel_file(cx, sp, &Path::new(file));
let mut error = None;
- let bytes = do io::read_error::cond.trap(|e| error = Some(e)).inside {
- do io::io_error::cond.trap(|e| error = Some(e)).inside {
- file.open_reader(io::Open).read_to_end()
- }
+ let bytes = do io::io_error::cond.trap(|e| error = Some(e)).inside {
+ file.open_reader(io::Open).read_to_end()
};
match error {
Some(e) => {
};
let mut error = None;
let bytes = do io::io_error::cond.trap(|e| error = Some(e)).inside {
- do io::read_error::cond.trap(|e| error = Some(e)).inside {
- path.open_reader(io::Open).read_to_end()
- }
+ path.open_reader(io::Open).read_to_end()
};
match error {
Some(e) => {