diff options
| author | bors <bors@rust-lang.org> | 2014-04-01 11:11:51 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-04-01 11:11:51 -0700 |
| commit | b71c02e512fcfe18ea7a5a8a99ac758b4fa564a6 (patch) | |
| tree | 7842aad2f7ad07256764e22d6ab2fad0b6f624ed /src/libnative | |
| parent | b8ef9fd9c9f642ce7b8aed82782a1ed745d08d64 (diff) | |
| parent | bc7a2d72a3fea324fa432de9b6ce6073302d3d8c (diff) | |
| download | rust-b71c02e512fcfe18ea7a5a8a99ac758b4fa564a6.tar.gz rust-b71c02e512fcfe18ea7a5a8a99ac758b4fa564a6.zip | |
auto merge of #13115 : huonw/rust/rand-errors, r=alexcrichton
move errno -> IoError converter into std, bubble up OSRng errors Also adds a general errno -> `~str` converter to `std::os`, and makes the failure messages for the things using `OSRng` (e.g. (transitively) the task-local RNG, meaning hashmap initialisation failures aren't such a black box).
Diffstat (limited to 'src/libnative')
| -rw-r--r-- | src/libnative/io/addrinfo.rs | 4 | ||||
| -rw-r--r-- | src/libnative/io/mod.rs | 67 | ||||
| -rw-r--r-- | src/libnative/io/net.rs | 2 | ||||
| -rw-r--r-- | src/libnative/io/process.rs | 2 |
4 files changed, 5 insertions, 70 deletions
diff --git a/src/libnative/io/addrinfo.rs b/src/libnative/io/addrinfo.rs index ff617e5a230..bca564870e2 100644 --- a/src/libnative/io/addrinfo.rs +++ b/src/libnative/io/addrinfo.rs @@ -96,10 +96,8 @@ extern "system" { #[cfg(windows)] fn get_error(_: c_int) -> IoError { - use super::translate_error; - unsafe { - translate_error(WSAGetLastError() as i32, true) + IoError::from_errno(WSAGetLastError() as uint, true) } } diff --git a/src/libnative/io/mod.rs b/src/libnative/io/mod.rs index e6e9cbb7ce3..34843102456 100644 --- a/src/libnative/io/mod.rs +++ b/src/libnative/io/mod.rs @@ -86,73 +86,10 @@ fn unimpl() -> IoError { } } -fn translate_error(errno: i32, detail: bool) -> IoError { - #[cfg(windows)] - fn get_err(errno: i32) -> (io::IoErrorKind, &'static str) { - match errno { - libc::EOF => (io::EndOfFile, "end of file"), - libc::ERROR_NO_DATA => (io::BrokenPipe, "the pipe is being closed"), - libc::ERROR_FILE_NOT_FOUND => (io::FileNotFound, "file not found"), - libc::ERROR_INVALID_NAME => (io::InvalidInput, "invalid file name"), - libc::WSAECONNREFUSED => (io::ConnectionRefused, "connection refused"), - libc::WSAECONNRESET => (io::ConnectionReset, "connection reset"), - libc::WSAEACCES => (io::PermissionDenied, "permission denied"), - libc::WSAEWOULDBLOCK => { - (io::ResourceUnavailable, "resource temporarily unavailable") - } - libc::WSAENOTCONN => (io::NotConnected, "not connected"), - libc::WSAECONNABORTED => (io::ConnectionAborted, "connection aborted"), - libc::WSAEADDRNOTAVAIL => (io::ConnectionRefused, "address not available"), - libc::WSAEADDRINUSE => (io::ConnectionRefused, "address in use"), - libc::ERROR_BROKEN_PIPE => (io::EndOfFile, "the pipe has ended"), - - // libuv maps this error code to EISDIR. we do too. if it is found - // to be incorrect, we can add in some more machinery to only - // return this message when ERROR_INVALID_FUNCTION after certain - // win32 calls. - libc::ERROR_INVALID_FUNCTION => (io::InvalidInput, - "illegal operation on a directory"), - - _ => (io::OtherIoError, "unknown error") - } - } - - #[cfg(not(windows))] - fn get_err(errno: i32) -> (io::IoErrorKind, &'static str) { - // FIXME: this should probably be a bit more descriptive... - match errno { - libc::EOF => (io::EndOfFile, "end of file"), - libc::ECONNREFUSED => (io::ConnectionRefused, "connection refused"), - libc::ECONNRESET => (io::ConnectionReset, "connection reset"), - libc::EPERM | libc::EACCES => - (io::PermissionDenied, "permission denied"), - libc::EPIPE => (io::BrokenPipe, "broken pipe"), - libc::ENOTCONN => (io::NotConnected, "not connected"), - libc::ECONNABORTED => (io::ConnectionAborted, "connection aborted"), - libc::EADDRNOTAVAIL => (io::ConnectionRefused, "address not available"), - libc::EADDRINUSE => (io::ConnectionRefused, "address in use"), - libc::ENOENT => (io::FileNotFound, "no such file or directory"), - libc::EISDIR => (io::InvalidInput, "illegal operation on a directory"), - - // These two constants can have the same value on some systems, but - // different values on others, so we can't use a match clause - x if x == libc::EAGAIN || x == libc::EWOULDBLOCK => - (io::ResourceUnavailable, "resource temporarily unavailable"), - - _ => (io::OtherIoError, "unknown error") - } - } - - let (kind, desc) = get_err(errno); - IoError { - kind: kind, - desc: desc, - detail: if detail {Some(os::last_os_error())} else {None}, - } +fn last_error() -> IoError { + IoError::last_error() } -fn last_error() -> IoError { translate_error(os::errno() as i32, true) } - // unix has nonzero values as errors fn mkerr_libc(ret: libc::c_int) -> IoResult<()> { if ret != 0 { diff --git a/src/libnative/io/net.rs b/src/libnative/io/net.rs index bf751be1f7f..6ddd69eb019 100644 --- a/src/libnative/io/net.rs +++ b/src/libnative/io/net.rs @@ -120,7 +120,7 @@ fn last_error() -> io::IoError { extern "system" { fn WSAGetLastError() -> libc::c_int; } - super::translate_error(unsafe { WSAGetLastError() }, true) + io::IoError::from_errno(unsafe { WSAGetLastError() } as uint, true) } #[cfg(not(windows))] diff --git a/src/libnative/io/process.rs b/src/libnative/io/process.rs index c729473eecd..d2e2db63c1b 100644 --- a/src/libnative/io/process.rs +++ b/src/libnative/io/process.rs @@ -481,7 +481,7 @@ fn spawn_process_os(config: p::ProcessConfig, (bytes[1] << 16) as i32 | (bytes[2] << 8) as i32 | (bytes[3] << 0) as i32; - Err(super::translate_error(errno, false)) + Err(io::IoError::from_errno(errno as uint, false)) } Err(e) => { assert!(e.kind == io::BrokenPipe || |
