Skip to content

Commit

Permalink
Auto merge of rust-lang#88220 - sunfishcode:sunfishcode/unix-listener…
Browse files Browse the repository at this point in the history
…-io-safety, r=joshtriplett

Implement `AsFd` etc. for `UnixListener`.

Implement `AsFd`, `From<OwnedFd>`, and `Into<OwnedFd>` for
`UnixListener`. This is a follow-up to rust-lang#87329.

r? `@joshtriplett`
  • Loading branch information
bors committed Aug 23, 2021
2 parents 1c04856 + a0ce5f2 commit 33fdb79
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion library/std/src/os/unix/net/listener.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{sockaddr_un, SocketAddr, UnixStream};
use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
use crate::path::Path;
use crate::sys::cvt;
use crate::sys::net::Socket;
Expand Down Expand Up @@ -262,6 +262,30 @@ impl IntoRawFd for UnixListener {
}
}

#[unstable(feature = "io_safety", issue = "87074")]
impl AsFd for UnixListener {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
self.0.as_inner().as_fd()
}
}

#[unstable(feature = "io_safety", issue = "87074")]
impl From<OwnedFd> for UnixListener {
#[inline]
fn from(fd: OwnedFd) -> UnixListener {
UnixListener(Socket::from_inner(FromInner::from_inner(fd)))
}
}

#[unstable(feature = "io_safety", issue = "87074")]
impl From<UnixListener> for OwnedFd {
#[inline]
fn from(listener: UnixListener) -> OwnedFd {
listener.0.into_inner().into_inner()
}
}

#[stable(feature = "unix_socket", since = "1.10.0")]
impl<'a> IntoIterator for &'a UnixListener {
type Item = io::Result<UnixStream>;
Expand Down

0 comments on commit 33fdb79

Please sign in to comment.