equal
deleted
inserted
replaced
2 |
2 |
3 use std::{ |
3 use std::{ |
4 io, io::{Error, ErrorKind, Write}, |
4 io, io::{Error, ErrorKind, Write}, |
5 net::{SocketAddr, IpAddr, Ipv4Addr}, |
5 net::{SocketAddr, IpAddr, Ipv4Addr}, |
6 collections::HashSet, |
6 collections::HashSet, |
7 mem::swap |
7 mem::{swap, replace} |
8 }; |
8 }; |
9 |
9 |
10 use mio::{ |
10 use mio::{ |
11 net::{TcpStream, TcpListener}, |
11 net::{TcpStream, TcpListener}, |
12 Poll, PollOpt, Ready, Token |
12 Poll, PollOpt, Ready, Token |
16 |
16 |
17 use utils; |
17 use utils; |
18 use protocol::{ProtocolDecoder, messages::*}; |
18 use protocol::{ProtocolDecoder, messages::*}; |
19 use super::{ |
19 use super::{ |
20 server::{HWServer}, |
20 server::{HWServer}, |
21 client::ClientId |
21 coretypes::ClientId |
22 }; |
22 }; |
23 |
23 |
24 const MAX_BYTES_PER_READ: usize = 2048; |
24 const MAX_BYTES_PER_READ: usize = 2048; |
25 |
25 |
26 #[derive(Hash, Eq, PartialEq, Copy, Clone)] |
26 #[derive(Hash, Eq, PartialEq, Copy, Clone)] |
275 !self.pending.is_empty() |
275 !self.pending.is_empty() |
276 } |
276 } |
277 |
277 |
278 pub fn on_idle(&mut self, poll: &Poll) -> io::Result<()> { |
278 pub fn on_idle(&mut self, poll: &Poll) -> io::Result<()> { |
279 if self.has_pending_operations() { |
279 if self.has_pending_operations() { |
280 let mut cache = Vec::new(); |
280 let mut cache = replace(&mut self.pending_cache, Vec::new()); |
281 swap(&mut cache, &mut self.pending_cache); |
|
282 cache.extend(self.pending.drain()); |
281 cache.extend(self.pending.drain()); |
283 for (id, state) in cache.drain(..) { |
282 for (id, state) in cache.drain(..) { |
284 match state { |
283 match state { |
285 NetworkClientState::NeedsRead => |
284 NetworkClientState::NeedsRead => |
286 self.client_readable(poll, id)?, |
285 self.client_readable(poll, id)?, |