async_transport/
proto.rs

1use std::net::{IpAddr, SocketAddr};
2
3/// Explicit congestion notification codepoint
4#[repr(u8)]
5#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
6pub enum EcnCodepoint {
7    #[doc(hidden)]
8    Ect0 = 0b10,
9    #[doc(hidden)]
10    Ect1 = 0b01,
11    #[doc(hidden)]
12    Ce = 0b11,
13}
14
15impl EcnCodepoint {
16    /// Create new object from the given bits
17    pub fn from_bits(x: u8) -> Option<Self> {
18        use self::EcnCodepoint::*;
19        Some(match x & 0b11 {
20            0b10 => Ect0,
21            0b01 => Ect1,
22            0b11 => Ce,
23            _ => {
24                return None;
25            }
26        })
27    }
28}
29
30#[derive(Debug)]
31pub struct Transmit {
32    /// The socket this datagram should be sent to
33    pub destination: SocketAddr,
34    /// Explicit congestion notification bits to set on the packet
35    pub ecn: Option<EcnCodepoint>,
36    /// Contents of the datagram
37    pub contents: Vec<u8>,
38    /// The segment size if this transmission contains multiple datagrams.
39    /// This is `None` if the transmit only contains a single datagram
40    pub segment_size: Option<usize>,
41    /// Optional source IP address for the datagram
42    pub src_ip: Option<IpAddr>,
43}