Skip to main content

dope_uring/sockets/reuse/
source.rs

1use crate::{
2    Backend,
3    sockets::reuse::{Installer, program},
4};
5use dope_sys::io::socket::route::{Plan, Source, count::Index};
6use std::os::fd::BorrowedFd;
7
8impl Source for Backend {
9    type Storage = [libc::sock_filter; program::MAX];
10    type Install<'a> = Installer<'a>;
11    type Ready = ();
12    type Lease<'a> = BorrowedFd<'a>;
13
14    const STORAGE: Self::Storage = [program::EMPTY; program::MAX];
15
16    fn try_prepare(
17        filter: &mut Self::Storage,
18        plan: Plan,
19    ) -> Result<(Self::Install<'_>, Self::Ready), Plan> {
20        let value = Installer {
21            plan,
22            filter: program::build(filter, plan, Some(Index::ZERO)),
23        };
24        Ok((value, ()))
25    }
26
27    fn lease<'a>((): &(), socket: BorrowedFd<'a>) -> Self::Lease<'a> {
28        socket
29    }
30}