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
use prelude::{Protocol, SockAddr, Endpoint};
use ffi::SOCK_SEQPACKET;
use seq_packet_socket::{SeqPacketSocket};
use socket_listener::{SocketListener};
use generic::GenericEndpoint;

#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
pub struct GenericSeqPacket {
    family: i32,
    protocol: i32,
    capacity: usize,
}

impl Protocol for GenericSeqPacket {
    type Endpoint = GenericEndpoint<Self>;

    fn family_type(&self) -> i32 {
        self.family
    }

    fn socket_type(&self) -> i32 {
        SOCK_SEQPACKET
    }

    fn protocol_type(&self) -> i32 {
        self.protocol
    }

    unsafe fn uninitialized(&self) -> Self::Endpoint {
        GenericEndpoint::default(self.capacity, self.protocol)
    }
}

impl Endpoint<GenericSeqPacket> for GenericEndpoint<GenericSeqPacket> {
    fn protocol(&self) -> GenericSeqPacket {
        GenericSeqPacket {
            family:  self.as_ref().sa_family as i32,
            protocol: self.protocol,
            capacity: self.capacity(),
        }
    }
}

pub type GenericSeqPacketEndpoint = GenericEndpoint<GenericSeqPacket>;

pub type GenericSeqPacketSocket = SeqPacketSocket<GenericSeqPacket>;

pub type GenericSeqPacketListener = SocketListener<GenericSeqPacket, SeqPacketSocket<GenericSeqPacket>>;