1use prelude::{Protocol, Endpoint};
2use ffi::{AF_UNIX, SOCK_DGRAM};
3use dgram_socket::DgramSocket;
4use local::{LocalProtocol, LocalEndpoint};
5
6use std::fmt;
7use std::mem;
8
9#[derive(Clone, Eq, PartialEq, Ord, PartialOrd)]
28pub struct LocalDgram;
29
30impl Protocol for LocalDgram {
31 type Endpoint = LocalEndpoint<Self>;
32
33 fn family_type(&self) -> i32 {
34 AF_UNIX
35 }
36
37 fn socket_type(&self) -> i32 {
38 SOCK_DGRAM
39 }
40
41 fn protocol_type(&self) -> i32 {
42 0
43 }
44
45 unsafe fn uninitialized(&self) -> Self::Endpoint {
46 mem::uninitialized()
47 }
48}
49
50impl LocalProtocol for LocalDgram {
51 type Socket = DgramSocket<Self>;
52}
53
54impl Endpoint<LocalDgram> for LocalEndpoint<LocalDgram> {
55 fn protocol(&self) -> LocalDgram {
56 LocalDgram
57 }
58}
59
60impl fmt::Debug for LocalDgram {
61 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
62 write!(f, "LocalDgram")
63 }
64}
65
66impl fmt::Debug for LocalEndpoint<LocalDgram> {
67 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
68 write!(f, "LocalEndpoint(Dgram:\"{}\")", self)
69 }
70}
71
72pub type LocalDgramEndpoint = LocalEndpoint<LocalDgram>;
74
75pub type LocalDgramSocket = DgramSocket<LocalDgram>;
77
78#[test]
79fn test_dgram() {
80 assert!(LocalDgram == LocalDgram);
81}
82
83#[test]
84fn test_format() {
85 use core::IoContext;
86
87 let ctx = &IoContext::new().unwrap();
88 println!("{:?}", LocalDgram);
89 println!("{:?}", LocalDgramEndpoint::new("foo/bar").unwrap());
90 println!("{:?}", LocalDgramSocket::new(ctx, LocalDgram).unwrap());
91}