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 374b957 commit ce19144
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use crate::handler;
use crate::packet;

use tokio::net::TcpListener;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpListener;

const SEPARATOR_LEN: usize = "\r\n".len();
const BUF_SIZE: usize = 1024 * 1;
Expand Down Expand Up @@ -45,7 +45,7 @@ impl Connection {
connection
}

pub async fn start(&mut self) {
pub async fn run(&mut self) {
// In a loop, read data from the socket and write the data back.
loop {
self.read().await;
Expand Down Expand Up @@ -151,6 +151,7 @@ pub struct Server {
port: u16,
path: String,
password: String,
connections: Vec<Connection>,
}

impl Server {
Expand All @@ -160,6 +161,7 @@ impl Server {
port: _port,
path: _path.to_string(),
password: _password.to_string(),
connections: Vec::new(),
}
}

Expand All @@ -177,8 +179,10 @@ impl Server {
let mut connection = Connection::new(socket, addr);
tracing::info!("New connection from {}", connection.to_string());

//self.connections.push(connection);

tokio::spawn(async move {
connection.start().await;
connection.run().await;
});
}
}
Expand Down

0 comments on commit ce19144

Please sign in to comment.