Skip to content

Commit cf9c4a3

Browse files
committed
kmc-solid: Implement AsFd and conversion to/from OwnedFd for {TcpStream,TcpListener,UdpSocket}
1 parent ddfe168 commit cf9c4a3

File tree

1 file changed

+26
-0
lines changed
  • library/std/src/os/solid

1 file changed

+26
-0
lines changed

library/std/src/os/solid/io.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,32 @@ impl AsFd for OwnedFd {
245245
}
246246
}
247247

248+
macro_rules! impl_owned_fd_traits {
249+
($($t:ident)*) => {$(
250+
impl AsFd for net::$t {
251+
#[inline]
252+
fn as_fd(&self) -> BorrowedFd<'_> {
253+
unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
254+
}
255+
}
256+
257+
impl From<net::$t> for OwnedFd {
258+
#[inline]
259+
fn from(socket: net::$t) -> OwnedFd {
260+
unsafe { Self::from_raw_fd(socket.into_raw_fd()) }
261+
}
262+
}
263+
264+
impl From<OwnedFd> for net::$t {
265+
#[inline]
266+
fn from(owned_fd: OwnedFd) -> Self {
267+
unsafe { Self::from_raw_fd(owned_fd.into_raw_fd()) }
268+
}
269+
}
270+
)*};
271+
}
272+
impl_owned_fd_traits! { TcpStream TcpListener UdpSocket }
273+
248274
/// A trait to extract the raw SOLID Sockets file descriptor from an underlying
249275
/// object.
250276
pub trait AsRawFd {

0 commit comments

Comments
 (0)