equal
deleted
inserted
replaced
4 use std::io::Write; |
4 use std::io::Write; |
5 use std::io; |
5 use std::io; |
6 |
6 |
7 use utils; |
7 use utils; |
8 use server::client::HWClient; |
8 use server::client::HWClient; |
|
9 use server::actions::Action; |
|
10 use server::actions::Action::*; |
9 |
11 |
10 type Slab<T> = slab::Slab<T, Token>; |
12 type Slab<T> = slab::Slab<T, Token>; |
11 |
13 |
12 pub struct HWServer { |
14 pub struct HWServer { |
13 listener: TcpListener, |
15 listener: TcpListener, |
42 Ok(()) |
44 Ok(()) |
43 } |
45 } |
44 |
46 |
45 pub fn client_readable(&mut self, poll: &Poll, |
47 pub fn client_readable(&mut self, poll: &Poll, |
46 token: Token) -> io::Result<()> { |
48 token: Token) -> io::Result<()> { |
47 self.clients[token].readable(poll) |
49 let actions; |
|
50 { |
|
51 actions = self.clients[token].readable(poll); |
|
52 } |
|
53 |
|
54 for action in actions { |
|
55 self.react(token, action); |
|
56 } |
|
57 Ok(()) |
48 } |
58 } |
49 |
59 |
50 pub fn client_writable(&mut self, poll: &Poll, |
60 pub fn client_writable(&mut self, poll: &Poll, |
51 token: Token) -> io::Result<()> { |
61 token: Token) -> io::Result<()> { |
52 self.clients[token].writable(poll) |
62 self.clients[token].writable(poll) |
54 |
64 |
55 pub fn client_error(&mut self, poll: &Poll, |
65 pub fn client_error(&mut self, poll: &Poll, |
56 token: Token) -> io::Result<()> { |
66 token: Token) -> io::Result<()> { |
57 self.clients[token].error(poll) |
67 self.clients[token].error(poll) |
58 } |
68 } |
|
69 |
|
70 fn react(&mut self, token: Token, action: Action) { |
|
71 match action { |
|
72 SendMe(msg) => self.clients[token].send_string(&msg), |
|
73 //_ => unimplemented!(), |
|
74 } |
|
75 } |
59 } |
76 } |
60 |
77 |
61 |
78 |
62 struct HWRoom { |
79 struct HWRoom { |
63 name: String |
80 name: String |