add extra apis

This commit is contained in:
Noah Kennedy
2023-10-20 12:07:44 -05:00
parent 9df15544fc
commit c03187281a
5 changed files with 40 additions and 3 deletions
+27
View File
@@ -243,6 +243,18 @@ impl<T: AsRawFd> AsyncFd<T> {
Self::new_with_handle_and_interest(inner, scheduler::Handle::current(), interest)
}
/// Create a new AsyncFd with the provided raw epoll flags for registration.
///
/// These flags replace any epoll flags would normally set when registering the fd.
#[track_caller]
#[cfg(all(target_os = "linux", tokio_unstable))]
pub fn with_flags(inner: T, flags: u32) -> io::Result<Self>
where
T: AsRawFd,
{
Self::new_with_handle_and_flags(inner, scheduler::Handle::current(), flags)
}
#[track_caller]
pub(crate) fn new_with_handle_and_interest(
inner: T,
@@ -260,6 +272,21 @@ impl<T: AsRawFd> AsyncFd<T> {
})
}
#[track_caller]
#[cfg(all(target_os = "linux", tokio_unstable))]
pub(crate) fn new_with_handle_and_flags(
mut inner: T,
handle: scheduler::Handle,
flags: u32,
) -> io::Result<Self> {
let registration = Registration::new_with_flags_and_handle(&mut inner, flags, handle)?;
Ok(AsyncFd {
registration,
inner: Some(inner),
})
}
/// Returns a shared reference to the backing object of this [`AsyncFd`].
#[inline]
pub fn get_ref(&self) -> &T {
+1 -1
View File
@@ -122,7 +122,7 @@ impl<E: std::os::unix::io::AsRawFd + Source> PollEvented<E> {
flags: u32,
handle: scheduler::Handle,
) -> io::Result<Self> {
let registration = Registration::new_with_interest_and_handle_raw(&mut io, flags, handle)?;
let registration = Registration::new_with_flags_and_handle(&mut io, flags, handle)?;
Ok(Self {
io: Some(io),
registration,
-1
View File
@@ -243,7 +243,6 @@ impl TcpListener {
/// Create a new TcpListener with the provided raw epoll flags.
///
/// These flags replace any epoll flags would normally set when registering the fd.
#[cfg(all(target_os = "linux"))]
#[track_caller]
#[cfg(all(target_os = "linux", tokio_unstable))]
pub fn from_std_with_flags(listener: net::TcpListener, flags: u32) -> io::Result<TcpListener> {
+11
View File
@@ -114,6 +114,17 @@ impl UnixListener {
Ok(UnixListener { io })
}
/// Create a new UnixListener with the provided raw epoll flags.
///
/// These flags replace any epoll flags would normally set when registering the fd.
#[track_caller]
#[cfg(all(target_os = "linux", tokio_unstable))]
pub fn from_std_with_flags(listener: net::UnixListener, flags: u32) -> io::Result<UnixListener> {
let io = mio::net::UnixListener::from_std(listener);
let io = PollEvented::new_raw(io, flags)?;
Ok(UnixListener { io })
}
/// Turns a [`tokio::net::UnixListener`] into a [`std::os::unix::net::UnixListener`].
///
/// The returned [`std::os::unix::net::UnixListener`] will have nonblocking mode
+1 -1
View File
@@ -90,7 +90,7 @@ impl Registration {
/// - `Ok` if the registration happened successfully
/// - `Err` if an error was encountered during registration
#[cfg(all(target_os = "linux", tokio_unstable))]
pub(crate) fn new_with_interest_and_handle_raw(
pub(crate) fn new_with_flags_and_handle(
io: &mut impl std::os::unix::io::AsRawFd,
flags: u32,
handle: scheduler::Handle,