Skip to main content

dope_sys/io/socket/record/
mod.rs

1use crate::Errno;
2
3mod packet;
4mod stream;
5
6pub use packet::Packet;
7pub use stream::Stream;
8
9/// A local transport carrying fixed u32 records through borrowed native prefixes.
10pub trait Transport {
11    /// Sends one record. Each successful leaf returns its completed input prefix.
12    fn send(
13        value: u32,
14        send: impl for<'a> FnMut(&'a [u8]) -> Result<&'a [u8], Errno>,
15    ) -> Result<(), Fault>;
16
17    /// Receives one record. Each successful leaf returns its initialized output prefix.
18    fn recv(recv: impl for<'a> FnMut(&'a mut [u8]) -> Result<&'a mut [u8], Errno>) -> Record;
19}
20
21#[derive(Debug)]
22pub struct Size {
23    pub expected: usize,
24    /// Observed payload extent, capped at five bytes for an oversized record.
25    pub actual: usize,
26}
27
28#[derive(Debug)]
29pub enum Fault {
30    Syscall(Errno),
31    Record(Size),
32}
33
34#[derive(Debug)]
35pub enum Record {
36    Value(u32),
37    Closed,
38    Failed(Fault),
39}
40
41#[derive(Clone, Copy, Debug, PartialEq, Eq)]
42#[repr(u8)]
43pub enum End {
44    Left,
45    Right,
46}
47
48#[derive(Clone, Copy, Debug, PartialEq, Eq)]
49pub enum Error {
50    Open(Errno),
51    Cloexec { end: End, error: crate::Cloexec },
52    Sigpipe { end: End, error: Errno },
53}