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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use prelude::{Protocol, Endpoint};
use ffi::{AF_UNIX, SOCK_DGRAM};
use dgram_socket::DgramSocket;
use local::{LocalProtocol, LocalEndpoint};
use std::fmt;
use std::mem;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd)]
pub struct LocalDgram;
impl Protocol for LocalDgram {
type Endpoint = LocalEndpoint<Self>;
fn family_type(&self) -> i32 {
AF_UNIX
}
fn socket_type(&self) -> i32 {
SOCK_DGRAM
}
fn protocol_type(&self) -> i32 {
0
}
unsafe fn uninitialized(&self) -> Self::Endpoint {
mem::uninitialized()
}
}
impl LocalProtocol for LocalDgram {
type Socket = DgramSocket<Self>;
}
impl Endpoint<LocalDgram> for LocalEndpoint<LocalDgram> {
fn protocol(&self) -> LocalDgram {
LocalDgram
}
}
impl fmt::Debug for LocalDgram {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "LocalDgram")
}
}
impl fmt::Debug for LocalEndpoint<LocalDgram> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "LocalEndpoint(Dgram:\"{}\")", self)
}
}
pub type LocalDgramEndpoint = LocalEndpoint<LocalDgram>;
pub type LocalDgramSocket = DgramSocket<LocalDgram>;
#[test]
fn test_dgram() {
assert!(LocalDgram == LocalDgram);
}
#[test]
fn test_format() {
use core::IoContext;
let ctx = &IoContext::new().unwrap();
println!("{:?}", LocalDgram);
println!("{:?}", LocalDgramEndpoint::new("foo/bar").unwrap());
println!("{:?}", LocalDgramSocket::new(ctx, LocalDgram).unwrap());
}