diff --git a/Cargo.toml b/Cargo.toml index 030c59b..df52f86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "unix_socket" -version = "0.4.1" +version = "0.4.2" authors = ["Steven Fackler "] license = "MIT" description = "Unix domain socket bindings" repository = "https://github.com/sfackler/rust-unix-socket" -documentation = "https://sfackler.github.io/rust-unix-socket/doc/v0.4.1/unix_socket" +documentation = "https://sfackler.github.io/rust-unix-socket/doc/v0.4.2/unix_socket" readme = "README.md" keywords = ["posix", "unix", "socket", "domain"] diff --git a/README.md b/README.md index 87ddee5..3beb117 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ Support for Unix domain socket clients and servers. -[Documentation](https://sfackler.github.io/rust-unix-socket/doc/v0.4.1/unix_socket) +[Documentation](https://sfackler.github.io/rust-unix-socket/doc/v0.4.2/unix_socket) diff --git a/src/lib.rs b/src/lib.rs index f8b3aeb..d170dc3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ //! Support for Unix domain socket clients and servers. #![warn(missing_docs)] -#![doc(html_root_url="https://sfackler.github.io/rust-unix-socket/doc/v0.4.1")] +#![doc(html_root_url="https://sfackler.github.io/rust-unix-socket/doc/v0.4.2")] #![cfg_attr(feature = "socket_timeout", feature(duration))] #![cfg_attr(all(test, feature = "socket_timeout"), feature(duration_span))] @@ -76,6 +76,15 @@ impl Inner { debug_assert_eq!(res, 0); Ok((Inner(fds[0]), Inner(fds[1]))) } + + fn try_clone(&self) -> io::Result { + let fd = unsafe { libc::dup(self.0) }; + if fd < 0 { + Err(io::Error::last_os_error()) + } else { + Ok(Inner(fd)) + } + } } unsafe fn sockaddr_un>(path: P) @@ -248,9 +257,7 @@ impl UnixStream { let inner = try!(Inner::new()); let (addr, len) = try!(sockaddr_un(path)); - let ret = libc::connect(inner.0, - &addr as *const _ as *const _, - len); + let ret = libc::connect(inner.0, &addr as *const _ as *const _, len); if ret < 0 { Err(io::Error::last_os_error()) } else { @@ -278,14 +285,9 @@ impl UnixStream { /// data, and options set on one stream will be propogated to the other /// stream. pub fn try_clone(&self) -> io::Result { - let fd = unsafe { libc::dup(self.inner.0) }; - if fd < 0 { - Err(io::Error::last_os_error()) - } else { - Ok(UnixStream { - inner: Inner(fd) - }) - } + Ok(UnixStream { + inner: try!(self.inner.try_clone()) + }) } /// Returns the socket address of the local half of this connection. @@ -323,8 +325,7 @@ impl UnixStream { } #[cfg(feature = "socket_timeout")] - fn set_timeout(&self, dur: Option, kind: libc::c_int) - -> io::Result<()> { + fn set_timeout(&self, dur: Option, kind: libc::c_int) -> io::Result<()> { let timeout = match dur { Some(dur) => { if dur.secs() == 0 && dur.extra_nanos() == 0 { @@ -541,9 +542,7 @@ impl UnixListener { let inner = try!(Inner::new()); let (addr, len) = try!(sockaddr_un(path)); - let ret = libc::bind(inner.0, - &addr as *const _ as *const _, - len); + let ret = libc::bind(inner.0, &addr as *const _ as *const _, len); if ret < 0 { return Err(io::Error::last_os_error()); } @@ -578,15 +577,10 @@ impl UnixListener { /// The returned `UnixListener` is a reference to the same socket that this /// object references. Both handles can be used to accept incoming /// connections and options set on one listener will affect the other. - pub fn try_clone(&self) -> io::Result { - let fd = unsafe { libc::dup(self.inner.0) }; - if fd < 0 { - Err(io::Error::last_os_error()) - } else { - Ok(UnixStream { - inner: Inner(fd) - }) - } + pub fn try_clone(&self) -> io::Result { + Ok(UnixListener { + inner: try!(self.inner.try_clone()) + }) } /// Returns the socket address of the local half of this connection.