Skip to content

Commit

Permalink
impl AsFd
Browse files Browse the repository at this point in the history
  • Loading branch information
DaughterOfMars committed Aug 15, 2024
1 parent 7019e8d commit 1d2869f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion msim-tokio/src/sim/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ use std::{
future::Future,
io,
net::SocketAddr as StdSocketAddr,
os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd},
os::{
fd::AsFd,
unix::{
io::{AsRawFd, FromRawFd, IntoRawFd, RawFd},
prelude::BorrowedFd,
},
},
pin::Pin,
sync::{
atomic::{AtomicBool, AtomicU32, Ordering},
Expand Down Expand Up @@ -734,6 +740,12 @@ impl TcpSocket {
}
}

impl AsFd for TcpSocket {
fn as_fd(&self) -> BorrowedFd<'_> {
self.fd.as_fd()
}
}

impl AsRawFd for TcpSocket {
fn as_raw_fd(&self) -> RawFd {
self.fd.as_raw_fd()
Expand All @@ -756,6 +768,12 @@ impl IntoRawFd for TcpSocket {
}
}

impl AsFd for TcpStream {
fn as_fd(&self) -> BorrowedFd<'_> {
unimplemented!("as_fd not supported in simulator")
}
}

// To support conversion between TcpStream <-> RawFd we will need to lower the TcpState
// and reading/writing operations to the net interceptor library - otherwise we can't track any
// reads/writes that occur while the stream is being manipulated as a raw fd.
Expand Down

0 comments on commit 1d2869f

Please sign in to comment.