Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement AsFd etc. for UnixListener. #88220

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(OwnedFd::from(fd))))
joshtriplett marked this conversation as resolved.
Show resolved Hide resolved
}
}

#[unstable(feature = "io_safety", issue = "87074")]
impl From<UnixListener> for OwnedFd {
#[inline]
fn from(listener: UnixListener) -> OwnedFd {
listener.0.into_inner().into_inner().into()
joshtriplett marked this conversation as resolved.
Show resolved Hide resolved
}
}

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