pal_async/fd.rs
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! File-descriptor readiness.
5
6use crate::interest::InterestSlot;
7use crate::interest::PollEvents;
8use std::io;
9use std::os::unix::prelude::*;
10use std::task::Context;
11use std::task::Poll;
12
13/// A trait for driving the polling of file descriptor readiness.
14pub trait FdReadyDriver: Unpin {
15 /// The file descriptor ready type.
16 type FdReady: 'static + PollFdReady;
17
18 /// Returns a new object for polling file descriptor readiness.
19 fn new_fd_ready(&self, fd: RawFd) -> io::Result<Self::FdReady>;
20}
21
22/// A trait for polling file descriptor readiness.
23pub trait PollFdReady: Unpin + Send + Sync {
24 /// Polls a file descriptor for readiness.
25 fn poll_fd_ready(
26 &mut self,
27 cx: &mut Context<'_>,
28 slot: InterestSlot,
29 events: PollEvents,
30 ) -> Poll<PollEvents>;
31
32 /// Clears cached socket readiness so that the next call to
33 /// `poll_socket_ready` will poll the OS again.
34 ///
35 /// With the epoll driver, this may not be sufficient for `poll_fd_ready` to
36 /// complete again--the caller must also ensure that the kernel has seen a
37 /// transition to a not-ready state (e.g. by seeing EAGAIN returned from `read`).
38 fn clear_fd_ready(&mut self, slot: InterestSlot);
39}