Skip to content

Commit 33fdb79

Browse files
committed
Auto merge of #88220 - sunfishcode:sunfishcode/unix-listener-io-safety, r=joshtriplett
Implement `AsFd` etc. for `UnixListener`. Implement `AsFd`, `From<OwnedFd>`, and `Into<OwnedFd>` for `UnixListener`. This is a follow-up to #87329. r? `@joshtriplett`
2 parents 1c04856 + a0ce5f2 commit 33fdb79

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

library/std/src/os/unix/net/listener.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::{sockaddr_un, SocketAddr, UnixStream};
2-
use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
2+
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
33
use crate::path::Path;
44
use crate::sys::cvt;
55
use crate::sys::net::Socket;
@@ -262,6 +262,30 @@ impl IntoRawFd for UnixListener {
262262
}
263263
}
264264

265+
#[unstable(feature = "io_safety", issue = "87074")]
266+
impl AsFd for UnixListener {
267+
#[inline]
268+
fn as_fd(&self) -> BorrowedFd<'_> {
269+
self.0.as_inner().as_fd()
270+
}
271+
}
272+
273+
#[unstable(feature = "io_safety", issue = "87074")]
274+
impl From<OwnedFd> for UnixListener {
275+
#[inline]
276+
fn from(fd: OwnedFd) -> UnixListener {
277+
UnixListener(Socket::from_inner(FromInner::from_inner(fd)))
278+
}
279+
}
280+
281+
#[unstable(feature = "io_safety", issue = "87074")]
282+
impl From<UnixListener> for OwnedFd {
283+
#[inline]
284+
fn from(listener: UnixListener) -> OwnedFd {
285+
listener.0.into_inner().into_inner()
286+
}
287+
}
288+
265289
#[stable(feature = "unix_socket", since = "1.10.0")]
266290
impl<'a> IntoIterator for &'a UnixListener {
267291
type Item = io::Result<UnixStream>;

0 commit comments

Comments
 (0)