|
1 | 1 | //! Support for Unix domain socket clients and servers.
|
2 | 2 | #![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")] |
4 | 4 | #![cfg_attr(feature = "socket_timeout", feature(duration))]
|
5 | 5 | #![cfg_attr(all(test, feature = "socket_timeout"), feature(duration_span))]
|
6 | 6 |
|
@@ -76,6 +76,15 @@ impl Inner {
|
76 | 76 | debug_assert_eq!(res, 0);
|
77 | 77 | Ok((Inner(fds[0]), Inner(fds[1])))
|
78 | 78 | }
|
| 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 | + } |
79 | 88 | }
|
80 | 89 |
|
81 | 90 | unsafe fn sockaddr_un<P: AsRef<Path>>(path: P)
|
@@ -248,9 +257,7 @@ impl UnixStream {
|
248 | 257 | let inner = try!(Inner::new());
|
249 | 258 | let (addr, len) = try!(sockaddr_un(path));
|
250 | 259 |
|
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); |
254 | 261 | if ret < 0 {
|
255 | 262 | Err(io::Error::last_os_error())
|
256 | 263 | } else {
|
@@ -278,14 +285,9 @@ impl UnixStream {
|
278 | 285 | /// data, and options set on one stream will be propogated to the other
|
279 | 286 | /// stream.
|
280 | 287 | 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 | + }) |
289 | 291 | }
|
290 | 292 |
|
291 | 293 | /// Returns the socket address of the local half of this connection.
|
@@ -323,8 +325,7 @@ impl UnixStream {
|
323 | 325 | }
|
324 | 326 |
|
325 | 327 | #[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<()> { |
328 | 329 | let timeout = match dur {
|
329 | 330 | Some(dur) => {
|
330 | 331 | if dur.secs() == 0 && dur.extra_nanos() == 0 {
|
@@ -541,9 +542,7 @@ impl UnixListener {
|
541 | 542 | let inner = try!(Inner::new());
|
542 | 543 | let (addr, len) = try!(sockaddr_un(path));
|
543 | 544 |
|
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); |
547 | 546 | if ret < 0 {
|
548 | 547 | return Err(io::Error::last_os_error());
|
549 | 548 | }
|
@@ -578,15 +577,10 @@ impl UnixListener {
|
578 | 577 | /// The returned `UnixListener` is a reference to the same socket that this
|
579 | 578 | /// object references. Both handles can be used to accept incoming
|
580 | 579 | /// 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 | + }) |
590 | 584 | }
|
591 | 585 |
|
592 | 586 | /// Returns the socket address of the local half of this connection.
|
|
0 commit comments