twizzler_net/
tx_req.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use crate::{
    addr::{Ipv4Addr, NodeAddr, ServiceAddr},
    req::{CloseInfo, ConnectionId, PacketData},
};

bitflags::bitflags! {
    #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug)]
    pub struct ListenFlags: u32 {
        const RAW = 0x1;
    }
}

#[repr(C)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug)]
pub struct ListenInfo {
    node_addr: NodeAddr,
    service_addr: ServiceAddr,
    flags: ListenFlags,
}

impl ListenInfo {
    pub fn address(&self) -> (NodeAddr, ServiceAddr) {
        (self.node_addr, self.service_addr)
    }

    pub fn flags(&self) -> ListenFlags {
        self.flags
    }

    pub fn new(node_addr: NodeAddr, service_addr: ServiceAddr, flags: ListenFlags) -> Self {
        Self {
            node_addr,
            service_addr,
            flags,
        }
    }
}

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub enum TxRequest {
    Echo(PacketData),
    SendToIpv4(Ipv4Addr, PacketData),
    ListenIpv4(Ipv4Addr),
    Connect(ListenInfo),
    Send(ConnectionId, PacketData),
    CloseConnection(ConnectionId, CloseInfo),
    Listen(ListenInfo),
    StopListen(ConnectionId),
    Close,
}

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub enum TxCompletionError {
    Unknown,
    InvalidArgument,
    NoSuchConnection,
}

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub enum TxCompletion {
    Nothing,
    ConnectionReady(ConnectionId),
    ListenReady(ConnectionId),
    Error(TxCompletionError),
}