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
use result::WebSocketResult;
use std::io::Result as IoResult;
use std::io::Write;
use stream::sync::AsTcpStream;
pub use stream::sync::Shutdown;
use ws;
use ws::dataframe::DataFrame;
use ws::sender::Sender as SenderTrait;
pub struct Writer<W> {
pub stream: W,
pub sender: Sender,
}
impl<W> Writer<W>
where
W: Write,
{
pub fn send_dataframe<D>(&mut self, dataframe: &D) -> WebSocketResult<()>
where
D: DataFrame,
W: Write,
{
self.sender.send_dataframe(&mut self.stream, dataframe)
}
pub fn send_message<M>(&mut self, message: &M) -> WebSocketResult<()>
where
M: ws::Message,
{
self.sender.send_message(&mut self.stream, message)
}
}
impl<S> Writer<S>
where
S: AsTcpStream + Write,
{
pub fn shutdown(&self) -> IoResult<()> {
self.stream.as_tcp().shutdown(Shutdown::Write)
}
pub fn shutdown_all(&self) -> IoResult<()> {
self.stream.as_tcp().shutdown(Shutdown::Both)
}
}
pub struct Sender {
mask: bool,
}
impl Sender {
pub fn new(mask: bool) -> Sender {
Sender { mask }
}
}
impl ws::Sender for Sender {
fn is_masked(&self) -> bool {
self.mask
}
}