diff options
-rw-r--r-- | src/errno.rs | 9 | ||||
-rw-r--r-- | src/fcntl.rs | 2 | ||||
-rw-r--r-- | src/sys/socket.rs | 19 | ||||
-rw-r--r-- | src/sys/wait.rs | 2 | ||||
-rw-r--r-- | src/unistd.rs | 10 |
5 files changed, 31 insertions, 11 deletions
diff --git a/src/errno.rs b/src/errno.rs index 60ccfde2..160c655c 100644 --- a/src/errno.rs +++ b/src/errno.rs @@ -4,6 +4,7 @@ use std::num::from_uint; use libc::c_int; pub use self::consts::*; +pub use self::consts::Errno::*; pub type SysResult<T> = Result<T, SysError>; @@ -672,9 +673,9 @@ mod consts { EQFULL = 106, } - pub const ELAST: Errno = EQFULL; - pub const EWOULDBLOCK: Errno = EAGAIN; - pub const EDEADLOCK: Errno = EDEADLK; + pub const ELAST: Errno = Errno::EQFULL; + pub const EWOULDBLOCK: Errno = Errno::EAGAIN; + pub const EDEADLOCK: Errno = Errno::EDEADLK; - pub const EL2NSYNC: Errno = UnknownErrno; + pub const EL2NSYNC: Errno = Errno::UnknownErrno; } diff --git a/src/fcntl.rs b/src/fcntl.rs index efd09500..93009bd8 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -100,6 +100,8 @@ pub enum FcntlArg<'a> { // TODO: Figure out how to handle value fcntl returns pub fn fcntl(fd: Fd, arg: FcntlArg) -> SysResult<()> { + use self::FcntlArg::*; + let res = unsafe { match arg { F_SETFD(flag) => ffi::fcntl(fd, ffi::F_SETFD, flag.bits()), diff --git a/src/sys/socket.rs b/src/sys/socket.rs index 36d181b5..8ce0e842 100644 --- a/src/sys/socket.rs +++ b/src/sys/socket.rs @@ -1,7 +1,7 @@ use std::{mem, ptr, fmt}; -use std::num::Int; use libc::{c_void, c_int, socklen_t, size_t, ssize_t}; -use fcntl::{Fd, fcntl, F_SETFL, F_SETFD, FD_CLOEXEC, O_NONBLOCK}; +use fcntl::{Fd, fcntl, FD_CLOEXEC, O_NONBLOCK}; +use fcntl::FcntlArg::{F_SETFD, F_SETFL}; use errno::{SysResult, SysError, from_ffi}; use features; @@ -257,6 +257,8 @@ pub fn listen(sockfd: Fd, backlog: uint) -> SysResult<()> { } pub fn bind(sockfd: Fd, addr: &SockAddr) -> SysResult<()> { + use self::SockAddr::*; + let res = unsafe { match *addr { SockIpV4(ref addr) => ffi::bind(sockfd, mem::transmute(addr), mem::size_of::<sockaddr_in>() as socklen_t), @@ -330,6 +332,8 @@ fn accept4_polyfill(sockfd: Fd, flags: SockFlag) -> SysResult<Fd> { } pub fn connect(sockfd: Fd, addr: &SockAddr) -> SysResult<()> { + use self::SockAddr::*; + let res = unsafe { match *addr { SockIpV4(ref addr) => ffi::connect(sockfd, mem::transmute(addr), mem::size_of::<sockaddr_in>() as socklen_t), @@ -344,7 +348,8 @@ pub fn connect(sockfd: Fd, addr: &SockAddr) -> SysResult<()> { mod sa_helpers { use std::mem; use libc::{sockaddr_storage, sockaddr_in, sockaddr_in6, sockaddr_un}; - use super::{SockAddr, SockIpV6, SockIpV4, SockUnix}; + use super::SockAddr; + use super::SockAddr::*; pub fn to_sockaddr_ipv4(addr: &sockaddr_storage) -> SockAddr { let sin : &sockaddr_in = unsafe { mem::transmute(addr) }; @@ -385,6 +390,8 @@ pub fn recvfrom(sockfd: Fd, buf: &mut [u8]) -> SysResult<(uint, SockAddr)> { } fn print_ipv4_addr(sin: &sockaddr_in, f: &mut fmt::Formatter) -> fmt::Result { + use std::num::Int; + let ip_addr = Int::from_be(sin.sin_addr.s_addr); let port = Int::from_be(sin.sin_port); @@ -399,7 +406,7 @@ fn print_ipv4_addr(sin: &sockaddr_in, f: &mut fmt::Formatter) -> fmt::Result { impl fmt::Show for SockAddr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - SockIpV4(sin) => print_ipv4_addr(&sin, f), + SockAddr::SockIpV4(sin) => print_ipv4_addr(&sin, f), _ => unimplemented!() } } @@ -420,6 +427,8 @@ fn sendto_sockaddr<T>(sockfd: Fd, buf: &[u8], flags: SockMessageFlags, addr: &T) } pub fn sendto(sockfd: Fd, buf: &[u8], addr: &SockAddr, flags: SockMessageFlags) -> SysResult<uint> { + use self::SockAddr::*; + let ret = match *addr { SockIpV4(ref addr) => sendto_sockaddr(sockfd, buf, flags, addr), SockIpV6(ref addr) => sendto_sockaddr(sockfd, buf, flags, addr), @@ -482,6 +491,8 @@ fn getsockname_sockaddr<T>(sockfd: Fd, addr: &T) -> SysResult<bool> { } pub fn getsockname(sockfd: Fd, addr: &mut SockAddr) -> SysResult<bool> { + use self::SockAddr::*; + match *addr { SockIpV4(ref addr) => getsockname_sockaddr(sockfd, addr), SockIpV6(ref addr) => getsockname_sockaddr(sockfd, addr), diff --git a/src/sys/wait.rs b/src/sys/wait.rs index 6f232bff..018f4062 100644 --- a/src/sys/wait.rs +++ b/src/sys/wait.rs @@ -21,6 +21,8 @@ pub enum WaitStatus { } pub fn waitpid(pid: pid_t, options: WaitPidFlag) -> SysResult<WaitStatus> { + use self::WaitStatus::*; + let mut status: i32 = 0; let res = unsafe { ffi::waitpid(pid as pid_t, &mut status as *mut c_int, options.bits()) }; diff --git a/src/unistd.rs b/src/unistd.rs index 1c8ed6ab..1dc7e7d8 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -1,7 +1,9 @@ use std::{mem, ptr}; use std::c_str::{CString, ToCStr}; use libc::{c_char, c_void, c_int, size_t, pid_t, off_t}; -use fcntl::{fcntl, Fd, OFlag, O_NONBLOCK, O_CLOEXEC, FD_CLOEXEC, F_SETFD, F_SETFL}; +use fcntl::{fcntl, Fd, OFlag, O_NONBLOCK, O_CLOEXEC, FD_CLOEXEC}; +use fcntl::FcntlArg::{F_SETFD, F_SETFL}; + use errno::{SysResult, SysError, from_ffi}; use core::raw::Slice as RawSlice; @@ -59,20 +61,22 @@ pub enum Fork { impl Fork { pub fn is_child(&self) -> bool { match *self { - Child => true, + Fork::Child => true, _ => false } } pub fn is_parent(&self) -> bool { match *self { - Parent(_) => true, + Fork::Parent(_) => true, _ => false } } } pub fn fork() -> SysResult<Fork> { + use self::Fork::*; + let res = unsafe { ffi::fork() }; if res < 0 { |