Browse Source

update async-std to 1.9.0

pull/34/head
jake 3 years ago
parent
commit
b79c2b3ae6
  1. 2
      Cargo.toml
  2. 14
      src/common/mainloop/client.rs
  3. 20
      src/common/mainloop/interserver.rs

2
Cargo.toml

@ -6,7 +6,7 @@ edition = "2018"
[dependencies]
libpso = { git = "http://git.sharnoth.com/jake/libpso" }
async-std = { version = "1.7.0", features = ["unstable", "attributes"] }
async-std = { version = "1.9.0", features = ["unstable", "attributes"] }
futures = "0.3.5"
rand = "0.7.3"
rand_chacha = "0.2.2"

14
src/common/mainloop/client.rs

@ -128,7 +128,7 @@ async fn send_pkt<S: SendServerPacket + Send + std::fmt::Debug>(socket: Arc<asyn
enum ClientAction<S, R> {
NewClient(ClientId, async_std::sync::Sender<S>),
NewClient(ClientId, async_std::channel::Sender<S>),
Packet(ClientId, R),
Disconnect(ClientId),
}
@ -142,8 +142,8 @@ enum ServerStateAction<S> {
fn client_recv_loop<S, R>(client_id: ClientId,
socket: Arc<async_std::net::TcpStream>,
cipher: Arc<Mutex<Box<dyn PSOCipher + Send>>>,
server_sender: async_std::sync::Sender<ClientAction<ServerStateAction<S>, R>>,
client_sender: async_std::sync::Sender<ServerStateAction<S>>)
server_sender: async_std::channel::Sender<ClientAction<ServerStateAction<S>, R>>,
client_sender: async_std::channel::Sender<ServerStateAction<S>>)
where
S: SendServerPacket + std::fmt::Debug + Send + 'static,
R: RecvServerPacket + std::fmt::Debug + Send + 'static,
@ -181,7 +181,7 @@ fn client_send_loop<S>(client_id: ClientId,
socket: Arc<async_std::net::TcpStream>,
cipher_in: Arc<Mutex<Box<dyn PSOCipher + Send>>>,
cipher_out: Arc<Mutex<Box<dyn PSOCipher + Send>>>,
client_receiver: async_std::sync::Receiver<ServerStateAction<S>>)
client_receiver: async_std::channel::Receiver<ServerStateAction<S>>)
where
S: SendServerPacket + std::fmt::Debug + Send + 'static,
{
@ -208,7 +208,7 @@ where
}
fn state_client_loop<STATE, S, R, E>(state: Arc<Mutex<STATE>>,
server_state_receiver: async_std::sync::Receiver<ClientAction<ServerStateAction<S>, R>>) where
server_state_receiver: async_std::channel::Receiver<ClientAction<ServerStateAction<S>, R>>) where
STATE: ServerState<SendPacket=S, RecvPacket=R, PacketError=E> + Send + 'static,
S: SendServerPacket + std::fmt::Debug + Send + 'static,
R: RecvServerPacket + std::fmt::Debug + Send + 'static,
@ -294,7 +294,7 @@ where
let listener = async_std::net::TcpListener::bind(&std::net::SocketAddr::from((std::net::Ipv4Addr::new(0,0,0,0), client_port))).await.unwrap();
let mut id = 0;
let (server_state_sender, server_state_receiver) = async_std::sync::channel(1024);
let (server_state_sender, server_state_receiver) = async_std::channel::bounded(1024);
state_client_loop(state, server_state_receiver);
loop {
@ -304,7 +304,7 @@ where
info!("new client {:?} {:?} {:?}", client_id, sock, addr);
let (client_sender, client_receiver) = async_std::sync::channel(64);
let (client_sender, client_receiver) = async_std::channel::bounded(64);
let socket = Arc::new(sock);
let cipher_in: Arc<Mutex<Box<dyn PSOCipher + Send>>> = Arc::new(Mutex::new(Box::new(NullCipher {})));
let cipher_out: Arc<Mutex<Box<dyn PSOCipher + Send>>> = Arc::new(Mutex::new(Box::new(NullCipher {})));

20
src/common/mainloop/interserver.rs

@ -49,12 +49,12 @@ impl MessageReceiver {
#[derive(Debug)]
enum InterserverInputAction<S, R> {
NewConnection(ServerId, async_std::sync::Sender<S>),
NewConnection(ServerId, async_std::channel::Sender<S>),
Message(ServerId, R),
Disconnect(ServerId),
}
async fn interserver_state_loop<A, S, R>(state: Arc<Mutex<A>>, action_receiver: async_std::sync::Receiver<InterserverInputAction<S, R>>)
async fn interserver_state_loop<A, S, R>(state: Arc<Mutex<A>>, action_receiver: async_std::channel::Receiver<InterserverInputAction<S, R>>)
where
A: InterserverActor<SendMessage=S, RecvMessage=R, Error=()> + Send + 'static,
S: Serialize + Send + 'static,
@ -114,8 +114,8 @@ where
async fn login_recv_loop<S, R>(server_id: ServerId,
socket: async_std::net::TcpStream,
state_loop_sender: async_std::sync::Sender<InterserverInputAction<S, R>>,
output_loop_sender: async_std::sync::Sender<S>)
state_loop_sender: async_std::channel::Sender<InterserverInputAction<S, R>>,
output_loop_sender: async_std::channel::Sender<S>)
where
S: Serialize + std::fmt::Debug + Send + 'static,
R: DeserializeOwned + std::fmt::Debug + Send + 'static,
@ -129,7 +129,7 @@ where
match msg_receiver.recv().await {
Ok(msg) => {
info!("[login recv loop msg] {:?}", msg);
state_loop_sender.send(InterserverInputAction::Message(server_id, msg)).await
state_loop_sender.send(InterserverInputAction::Message(server_id, msg)).await;
},
Err(err) => {
if let MessageReceiverError::Disconnected = err {
@ -146,7 +146,7 @@ where
async fn interserver_send_loop<S>(server_id: ServerId,
mut socket: async_std::net::TcpStream,
output_loop_receiver: async_std::sync::Receiver<S>)
output_loop_receiver: async_std::channel::Receiver<S>)
where
S: Serialize + std::fmt::Debug + Send + 'static,
{
@ -185,7 +185,7 @@ pub fn login_listen_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<Chara
let listener = async_std::net::TcpListener::bind(&std::net::SocketAddr::from((std::net::Ipv4Addr::new(0,0,0,0), port))).await.unwrap();
let mut id = 0;
let (server_state_sender, server_state_receiver) = async_std::sync::channel(1024);
let (server_state_sender, server_state_receiver) = async_std::channel::bounded(1024);
interserver_state_loop(state.clone(), server_state_receiver).await;
loop {
@ -194,7 +194,7 @@ pub fn login_listen_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<Chara
id += 1;
let server_id = crate::common::interserver::ServerId(id);
let (client_sender, client_receiver) = async_std::sync::channel(64);
let (client_sender, client_receiver) = async_std::channel::bounded(64);
{
let mut state = state.lock().await;
@ -213,7 +213,7 @@ pub fn login_listen_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<Chara
pub fn ship_connect_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<ShipServerState<EG>>>, ip: std::net::Ipv4Addr, port: u16) -> Pin<Box<dyn Future<Output = ()>>> {
Box::pin(async_std::task::spawn(async move {
let mut id = 0;
let (server_state_sender, server_state_receiver) = async_std::sync::channel(1024);
let (server_state_sender, server_state_receiver) = async_std::channel::bounded(1024);
interserver_state_loop(state.clone(), server_state_receiver).await;
@ -230,7 +230,7 @@ pub fn ship_connect_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<ShipS
id += 1;
let server_id = crate::common::interserver::ServerId(id);
info!("found loginserv: {:?} {:?}", server_id, socket);
let (client_sender, client_receiver) = async_std::sync::channel(64);
let (client_sender, client_receiver) = async_std::channel::bounded(64);
{
let mut state = state.lock().await;

Loading…
Cancel
Save