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

Commit 21b9cfd

Browse files
committed
Merge branch 'release-v0.4.2' into release
2 parents 646d475 + 8cee3d3 commit 21b9cfd

File tree

3 files changed

+23
-29
lines changed

3 files changed

+23
-29
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
22
name = "unix_socket"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
authors = ["Steven Fackler <[email protected]>"]
55
license = "MIT"
66
description = "Unix domain socket bindings"
77
repository = "https://github.com/sfackler/rust-unix-socket"
8-
documentation = "https://sfackler.github.io/rust-unix-socket/doc/v0.4.1/unix_socket"
8+
documentation = "https://sfackler.github.io/rust-unix-socket/doc/v0.4.2/unix_socket"
99
readme = "README.md"
1010
keywords = ["posix", "unix", "socket", "domain"]
1111

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
Support for Unix domain socket clients and servers.
66

7-
[Documentation](https://sfackler.github.io/rust-unix-socket/doc/v0.4.1/unix_socket)
7+
[Documentation](https://sfackler.github.io/rust-unix-socket/doc/v0.4.2/unix_socket)

src/lib.rs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Support for Unix domain socket clients and servers.
22
#![warn(missing_docs)]
3-
#![doc(html_root_url="https://sfackler.github.io/rust-unix-socket/doc/v0.4.1")]
3+
#![doc(html_root_url="https://sfackler.github.io/rust-unix-socket/doc/v0.4.2")]
44
#![cfg_attr(feature = "socket_timeout", feature(duration))]
55
#![cfg_attr(all(test, feature = "socket_timeout"), feature(duration_span))]
66

@@ -76,6 +76,15 @@ impl Inner {
7676
debug_assert_eq!(res, 0);
7777
Ok((Inner(fds[0]), Inner(fds[1])))
7878
}
79+
80+
fn try_clone(&self) -> io::Result<Inner> {
81+
let fd = unsafe { libc::dup(self.0) };
82+
if fd < 0 {
83+
Err(io::Error::last_os_error())
84+
} else {
85+
Ok(Inner(fd))
86+
}
87+
}
7988
}
8089

8190
unsafe fn sockaddr_un<P: AsRef<Path>>(path: P)
@@ -248,9 +257,7 @@ impl UnixStream {
248257
let inner = try!(Inner::new());
249258
let (addr, len) = try!(sockaddr_un(path));
250259

251-
let ret = libc::connect(inner.0,
252-
&addr as *const _ as *const _,
253-
len);
260+
let ret = libc::connect(inner.0, &addr as *const _ as *const _, len);
254261
if ret < 0 {
255262
Err(io::Error::last_os_error())
256263
} else {
@@ -278,14 +285,9 @@ impl UnixStream {
278285
/// data, and options set on one stream will be propogated to the other
279286
/// stream.
280287
pub fn try_clone(&self) -> io::Result<UnixStream> {
281-
let fd = unsafe { libc::dup(self.inner.0) };
282-
if fd < 0 {
283-
Err(io::Error::last_os_error())
284-
} else {
285-
Ok(UnixStream {
286-
inner: Inner(fd)
287-
})
288-
}
288+
Ok(UnixStream {
289+
inner: try!(self.inner.try_clone())
290+
})
289291
}
290292

291293
/// Returns the socket address of the local half of this connection.
@@ -323,8 +325,7 @@ impl UnixStream {
323325
}
324326

325327
#[cfg(feature = "socket_timeout")]
326-
fn set_timeout(&self, dur: Option<std::time::Duration>, kind: libc::c_int)
327-
-> io::Result<()> {
328+
fn set_timeout(&self, dur: Option<std::time::Duration>, kind: libc::c_int) -> io::Result<()> {
328329
let timeout = match dur {
329330
Some(dur) => {
330331
if dur.secs() == 0 && dur.extra_nanos() == 0 {
@@ -541,9 +542,7 @@ impl UnixListener {
541542
let inner = try!(Inner::new());
542543
let (addr, len) = try!(sockaddr_un(path));
543544

544-
let ret = libc::bind(inner.0,
545-
&addr as *const _ as *const _,
546-
len);
545+
let ret = libc::bind(inner.0, &addr as *const _ as *const _, len);
547546
if ret < 0 {
548547
return Err(io::Error::last_os_error());
549548
}
@@ -578,15 +577,10 @@ impl UnixListener {
578577
/// The returned `UnixListener` is a reference to the same socket that this
579578
/// object references. Both handles can be used to accept incoming
580579
/// connections and options set on one listener will affect the other.
581-
pub fn try_clone(&self) -> io::Result<UnixStream> {
582-
let fd = unsafe { libc::dup(self.inner.0) };
583-
if fd < 0 {
584-
Err(io::Error::last_os_error())
585-
} else {
586-
Ok(UnixStream {
587-
inner: Inner(fd)
588-
})
589-
}
580+
pub fn try_clone(&self) -> io::Result<UnixListener> {
581+
Ok(UnixListener {
582+
inner: try!(self.inner.try_clone())
583+
})
590584
}
591585

592586
/// Returns the socket address of the local half of this connection.

0 commit comments

Comments
 (0)