Skip to main content

dope_core/driver/
completion.rs

1use std::io;
2use std::time::Duration;
3
4use super::DriverContext;
5use crate::backend::Backend;
6use crate::backend::ops::completion::CompletionBackend;
7use crate::io::Event;
8
9pub trait Completion<'d> {
10    fn drain(&mut self, buf: &mut [Option<Event<'d>>]) -> usize;
11    fn wait(&mut self, timeout: Option<Duration>) -> io::Result<()>;
12}
13
14impl<'d> Completion<'d> for DriverContext<'_, 'd> {
15    fn drain(&mut self, buf: &mut [Option<Event<'d>>]) -> usize {
16        self.flush_returned_buffers();
17        let reference = self.driver_ref();
18        <Backend as CompletionBackend>::drain(self.backend(), reference, buf)
19    }
20
21    fn wait(&mut self, timeout: Option<Duration>) -> io::Result<()> {
22        self.flush_returned_buffers();
23        <Backend as CompletionBackend>::wait(self.backend(), timeout)
24    }
25}