From 197e74bca3745782e80549725b578d2259922ac1 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 2 Jun 2015 23:33:49 -0700 Subject: [PATCH 1/4] Cleanup --- src/lib.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f8b3aeb..0fe8d70 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -248,9 +248,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 { @@ -323,8 +321,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 +538,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()); } From 72180e8dd86626476d438a60d021bc82277103fa Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 7 Jun 2015 08:45:24 -0700 Subject: [PATCH 2/4] Fix UnixListener::try_clone signature Closes #11 --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0fe8d70..03bb719 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -573,12 +573,12 @@ 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 { + 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 { + Ok(UnixListener { inner: Inner(fd) }) } From 3e3b7c1f33671ad758d660a8aa7e36b513b3ed27 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 7 Jun 2015 08:47:29 -0700 Subject: [PATCH 3/4] Remove some duplicated logic --- src/lib.rs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 03bb719..83e8546 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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) @@ -276,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. @@ -574,14 +578,9 @@ impl UnixListener { /// 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(UnixListener { - inner: Inner(fd) - }) - } + Ok(UnixListener { + inner: try!(self.inner.try_clone()) + }) } /// Returns the socket address of the local half of this connection. From 8cee3d3bed29c19d1574a55d63e93b96c967e09c Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 7 Jun 2015 08:50:01 -0700 Subject: [PATCH 4/4] Release v0.4.2 --- Cargo.toml | 4 ++-- README.md | 2 +- src/lib.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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 83e8546..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))]