asyncio/generic/
dgram.rs

1use prelude::{Protocol, SockAddr, Endpoint};
2use ffi::SOCK_DGRAM;
3use dgram_socket::DgramSocket;
4use generic::GenericEndpoint;
5
6#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
7pub struct GenericDgram {
8    family: i32,
9    protocol: i32,
10    capacity: usize,
11}
12
13impl Protocol for GenericDgram {
14    type Endpoint = GenericEndpoint<Self>;
15
16    fn family_type(&self) -> i32 {
17        self.family
18    }
19
20    fn socket_type(&self) -> i32 {
21        SOCK_DGRAM
22    }
23
24    fn protocol_type(&self) -> i32 {
25        self.protocol
26    }
27
28    unsafe fn uninitialized(&self) -> Self::Endpoint {
29        GenericEndpoint::default(self.capacity, self.protocol)
30    }
31}
32
33impl Endpoint<GenericDgram> for GenericEndpoint<GenericDgram> {
34    fn protocol(&self) -> GenericDgram {
35        GenericDgram {
36            family: self.as_ref().sa_family as i32,
37            protocol: self.protocol,
38            capacity: self.capacity(),
39        }
40    }
41}
42
43pub type GenericDgramEndpoint = GenericEndpoint<GenericDgram>;
44
45pub type GenericDgramSocket = DgramSocket<GenericDgram>;