diff --git a/Cargo.toml b/Cargo.toml index edca595..7f2e570 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = "4.5.4" serde_json = "1.0.117" tokio = { version = "1.37.0", features = ["full"] } tracing = "0.1.40" diff --git a/src/handler/mod.rs b/src/handler/mod.rs index 8685fd6..4221f87 100644 --- a/src/handler/mod.rs +++ b/src/handler/mod.rs @@ -17,8 +17,11 @@ pub fn handle(json: &str) { println!("{}: {:?}", "val", val["method"]); match method { + "enter" => { + enter::handle(&val); + } "login" => { - login_handler::handle(&val); + login::handle(&val); } _ => { tracing::error!("Unkown method request: {:?}", method); @@ -26,7 +29,13 @@ pub fn handle(json: &str) { } } -mod login_handler { +mod enter { + pub fn handle(json: &serde_json::Value) { + tracing::trace!("method: {:?}", json["method"]); + } +} + +mod login { pub fn handle(json: &serde_json::Value) { tracing::trace!("method: {:?}", json["method"]); } diff --git a/src/main.rs b/src/main.rs index ed6f2d0..0e92bfc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,17 @@ #![allow(dead_code)] +#![allow(unused_imports)] -mod server; mod handler; mod packet; +mod server; use server::Server; use std::io; use tracing_subscriber::{fmt, layer::SubscriberExt}; +use clap::{arg, Command}; + /// Setup logger rotator. /// /// https://docs.rs/tracing-appender/0.2.3/tracing_appender/non_blocking/struct.WorkerGuard.html @@ -26,6 +29,20 @@ pub fn setup_logger() -> tracing_appender::non_blocking::WorkerGuard { #[tokio::main] async fn main() { let _guard = setup_logger(); - let mut server = Server::new("127.0.0.1".to_string(), 8080); + + let matches = Command::new("Cogru") + .version("0.1.0") + .about("Where the collaboration start!?") + .arg( + arg!(--port ) + .required(false) + .help("Port number") + .default_value("8786"), + ) + .get_matches(); + + let port = matches.get_one::("port").unwrap().parse::().unwrap(); + + let mut server = Server::new("127.0.0.1".to_string(), port); let _ = server.start().await; } diff --git a/src/server.rs b/src/server.rs index c28c8fd..7c7cc2b 100644 --- a/src/server.rs +++ b/src/server.rs @@ -13,7 +13,7 @@ use tokio::net::TcpListener; use tokio::io::{AsyncReadExt, AsyncWriteExt}; const SEPARATOR_LEN: usize = "\r\n".len(); -const BUF_SIZE: usize = 1024; +const BUF_SIZE: usize = 1024 * 1; fn get_content_len(line: &str) -> usize { if !line.starts_with("Content-Length: ") {