Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed May 20, 2024
1 parent 3a337fa commit 410ebff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
21 changes: 11 additions & 10 deletions src/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
* $Notice: See LICENSE.txt for modification and distribution information
* Copyright © 2024 by Shen, Jen-Chieh $
*/
use crate::server;

pub fn handle(json: &str) {
pub fn handle(connection: &mut server::Connection, json: &str) {
let v = serde_json::from_str(json);
let val: serde_json::Value = v.unwrap();

Expand All @@ -18,25 +19,25 @@ pub fn handle(json: &str) {

match method {
"enter" => {
enter::handle(&val);
enter::handle(connection, &val);
}
"login" => {
login::handle(&val);
"exit" => {
// TODO: ..
}
_ => {
tracing::error!("Unkown method request: {:?}", method);
}
}
}

/// Enter session
mod enter {
pub fn handle(json: &serde_json::Value) {
tracing::trace!("method: {:?}", json["method"]);
}
}
use crate::server;

mod login {
pub fn handle(json: &serde_json::Value) {
pub fn handle(connection: &mut server::Connection, json: &serde_json::Value) {
tracing::trace!("method: {:?}", json["method"]);
connection.send(serde_json::json!({
"": "",
}));
}
}
4 changes: 2 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn get_content_len(line: &str) -> usize {
len_str.parse::<usize>().unwrap()
}

struct Connection {
pub struct Connection {
pub stream: tokio::net::TcpStream,
pub addr: std::net::SocketAddr,
read_buf: [u8; BUF_SIZE],
Expand Down Expand Up @@ -111,7 +111,7 @@ impl Connection {
boundary += content_len;

let data = &line[..content_len];
handler::handle(data);
handler::handle(&mut self, data);

Check failure on line 114 in src/server.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

cannot borrow `self` as mutable, as it is not declared as mutable

Check failure on line 114 in src/server.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

cannot borrow `self` as mutable because it is also borrowed as immutable

Check failure on line 114 in src/server.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

cannot borrow `self` as mutable, as it is not declared as mutable

Check failure on line 114 in src/server.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

cannot borrow `self` as mutable because it is also borrowed as immutable

Check failure on line 114 in src/server.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

cannot borrow `self` as mutable, as it is not declared as mutable

Check failure on line 114 in src/server.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

cannot borrow `self` as mutable because it is also borrowed as immutable
//println!("{}: {}", "receive all", data);

process = true;
Expand Down

0 comments on commit 410ebff

Please sign in to comment.