Skip to main content

dope_core/driver/
recv.rs

1use super::DriverContext;
2use crate::backend::Backend;
3use crate::backend::ops::buffers::BufferBackend;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
6pub struct Config {
7    pub len: usize,
8    pub entries: u16,
9}
10
11impl Config {
12    pub fn for_accept(accept_slots: u32, buf_len: usize, max_entries: u32) -> Self {
13        const FLOOR: u32 = 1024;
14        const PER_CONNECTION: u32 = 4;
15        const DRAIN_BATCH: u32 = 256;
16
17        let buf_len_ratio = (buf_len / 4096).max(1) as u32;
18        let high_water_mark = PER_CONNECTION
19            .saturating_mul(DRAIN_BATCH)
20            .min(accept_slots.max(FLOOR));
21        let target = high_water_mark.min(max_entries) / buf_len_ratio;
22        Self {
23            len: buf_len,
24            entries: target.max(FLOOR).min(u16::MAX as u32) as u16,
25        }
26    }
27
28    pub fn apply_overrides(&mut self, len: usize, entries: u16) {
29        if len != 0 {
30            self.len = len;
31        }
32        if entries != 0 {
33            self.entries = entries;
34        }
35    }
36}
37
38pub trait Buffers {
39    fn buffer_group(&self) -> u16;
40    fn buffer_len(&self) -> usize;
41    fn buffer_count(&self) -> usize;
42}
43
44impl Buffers for DriverContext<'_, '_> {
45    fn buffer_group(&self) -> u16 {
46        <Backend as BufferBackend>::buffer_group(self.backend_ref())
47    }
48
49    fn buffer_len(&self) -> usize {
50        <Backend as BufferBackend>::buffer_len(self.backend_ref())
51    }
52
53    fn buffer_count(&self) -> usize {
54        <Backend as BufferBackend>::buffer_count(self.backend_ref())
55    }
56}