1use std::fmt;
2use std::mem;
3
4pub trait SockAddr : Clone + Send + 'static {
5 type SockAddr : ?Sized;
6
7 fn as_ref(&self) -> &Self::SockAddr;
8
9 unsafe fn as_mut(&mut self) -> &mut Self::SockAddr;
10
11 fn capacity(&self) -> usize;
12
13 fn size(&self) -> usize;
14
15 unsafe fn resize(&mut self, size: usize);
16}
17
18pub trait Endpoint<P> : SockAddr {
19 fn protocol(&self) -> P;
20}
21
22pub trait Protocol : fmt::Debug + Clone + Send + 'static {
23 type Endpoint : Endpoint<Self>;
24
25 fn family_type(&self) -> i32;
27
28 fn socket_type(&self) -> i32;
30
31 fn protocol_type(&self) -> i32;
33
34 unsafe fn uninitialized(&self) -> Self::Endpoint;
35}
36
37pub trait IoControl {
38 type Data;
39
40 #[cfg(unix)] fn name(&self) -> u64;
41 #[cfg(windows)] fn name(&self) -> i32;
42
43 fn data(&mut self) -> &mut Self::Data;
44}
45
46pub trait SocketOption<P> {
47 type Data;
48
49 fn level(&self, pro: &P) -> i32;
50
51 fn name(&self, pro: &P) -> i32;
52}
53
54pub trait GetSocketOption<P> : SocketOption<P> + Default {
55 fn capacity(&self) -> usize {
56 mem::size_of::<Self::Data>()
57 }
58
59 fn data_mut(&mut self) -> &mut Self::Data;
60
61 fn resize(&mut self, _size: usize) {
62 }
63}
64
65pub trait SetSocketOption<P> : SocketOption<P> {
66 fn data(&self) -> &Self::Data;
67
68 fn size(&self) -> usize {
69 mem::size_of::<Self::Data>()
70 }
71}