Skip to content
This repository has been archived by the owner on May 17, 2018. It is now read-only.

Commit

Permalink
Merge branch 'release-v0.4.2' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Jun 7, 2015
2 parents 646d475 + 8cee3d3 commit 21b9cfd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "unix_socket"
version = "0.4.1"
version = "0.4.2"
authors = ["Steven Fackler <[email protected]>"]
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"]

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
46 changes: 20 additions & 26 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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))]

Expand Down Expand Up @@ -76,6 +76,15 @@ impl Inner {
debug_assert_eq!(res, 0);
Ok((Inner(fds[0]), Inner(fds[1])))
}

fn try_clone(&self) -> io::Result<Inner> {
let fd = unsafe { libc::dup(self.0) };
if fd < 0 {
Err(io::Error::last_os_error())
} else {
Ok(Inner(fd))
}
}
}

unsafe fn sockaddr_un<P: AsRef<Path>>(path: P)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<UnixStream> {
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.
Expand Down Expand Up @@ -323,8 +325,7 @@ impl UnixStream {
}

#[cfg(feature = "socket_timeout")]
fn set_timeout(&self, dur: Option<std::time::Duration>, kind: libc::c_int)
-> io::Result<()> {
fn set_timeout(&self, dur: Option<std::time::Duration>, kind: libc::c_int) -> io::Result<()> {
let timeout = match dur {
Some(dur) => {
if dur.secs() == 0 && dur.extra_nanos() == 0 {
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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<UnixStream> {
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<UnixListener> {
Ok(UnixListener {
inner: try!(self.inner.try_clone())
})
}

/// Returns the socket address of the local half of this connection.
Expand Down

0 comments on commit 21b9cfd

Please sign in to comment.