|
|
@ -6,7 +6,7 @@ use std::net::{SocketAddr, Ipv4Addr}; |
|
|
|
use std::sync::mpsc::TryRecvError;
|
|
|
|
use mio::tcp::TcpListener;
|
|
|
|
use mio::{Events, Poll, Token, Ready, PollOpt};
|
|
|
|
use log::warn;
|
|
|
|
use log::{info, warn};
|
|
|
|
|
|
|
|
use crate::common::client::Client;
|
|
|
|
use crate::common::serverstate::{SendServerPacket, RecvServerPacket, ClientId};
|
|
|
@ -48,6 +48,7 @@ pub enum ClientAction<S> { |
|
|
|
pub enum ClientPoolAction<R> {
|
|
|
|
NewClient(ClientId),
|
|
|
|
Packet(ClientId, R),
|
|
|
|
Disconnect(ClientId),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -127,7 +128,6 @@ impl<S, R> ClientPool<S, R> where |
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
@ -146,7 +146,6 @@ impl<S, R> ClientPool<S, R> where |
|
|
|
Token(0) => self.new_client(),
|
|
|
|
Token(1) => self.packet_to_send(),
|
|
|
|
_ => {
|
|
|
|
|
|
|
|
let client_id = match self.client_ids.get(&event.token()) {
|
|
|
|
Some(client_id) => client_id,
|
|
|
|
None => continue,
|
|
|
@ -164,12 +163,15 @@ impl<S, R> ClientPool<S, R> where |
|
|
|
match client_read(&self.sender, client) {
|
|
|
|
Ok(()) =>{},
|
|
|
|
Err(err) => {
|
|
|
|
warn!("pkt err: {:?}", err);
|
|
|
|
match err {
|
|
|
|
PacketNetworkError::ClientDisconnected => {
|
|
|
|
info!("client {:?} disconnected", client_id);
|
|
|
|
self.poll.deregister(&client.socket).unwrap();
|
|
|
|
self.sender.send(ClientPoolAction::Disconnect(*client_id)).unwrap();
|
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
warn!("pkt err: {:?}", err);
|
|
|
|
},
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|