My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nomicon/games/rstnode/rst-core/src/net/handler.rs

26 lines
714 B

use crate::{
net::Client,
server::Server,
wire::{Request, Response},
};
use async_std::sync::{Arc, Receiver, Sender};
use std::net::SocketAddr;
/// A handler task wrapper to execute
pub struct Handler {
peer: SocketAddr,
tx: Sender<(SocketAddr, Response)>,
server: Arc<Server>,
}
impl Handler {
pub fn new(peer: SocketAddr, tx: Sender<(SocketAddr, Response)>, server: Arc<Server>) -> Self {
Self { peer, tx, server }
}
/// Start a message handler with a handle to send a reply back to the clients
pub async fn run(self, req: Request) {
let resp = crate::net::parser::request(req, self.server).await;
self.tx.send((self.peer, resp)).await;
}
}