Skip to content

Commit

Permalink
feature: dont match tcp listener binding use let to store listener an…
Browse files Browse the repository at this point in the history
…d use except on it
  • Loading branch information
Ando committed Aug 14, 2023
1 parent cbdf86d commit e79f5ed
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod server {

impl Server {
pub fn new() {}

Check warning on line 11 in src/lib.rs

View workflow job for this annotation

GitHub Actions / lint

methods called `new` usually return `Self`

Check warning on line 11 in src/lib.rs

View workflow job for this annotation

GitHub Actions / lint

methods called `new` usually return `Self`

pub fn listen(host: &str, port: u32) {
let mut addr = String::new();

Expand All @@ -24,21 +25,20 @@ pub mod server {
addr.push(':');
addr.push_str(&port.to_string());

let listener = TcpListener::bind(&addr).expect("An error occured while listening app");

println!("App is listening on {}", &addr);

match TcpListener::bind(&addr) {
Ok(listener) => {
for stream in listener.incoming() {
match stream {
Ok(tcp_stream) => thread::spawn(move || self::Server::handle_connection(tcp_stream)),
Err(e) => panic!("{}", e),
};
}
}
Err(e) => panic!("{}", e),
for stream in listener.incoming() {
match stream {
Ok(tcp_stream) => thread::spawn(move || self::Server::handle_connection(tcp_stream)),
Err(e) => panic!("{}", e),
};
}
}

pub fn close() {}

fn handle_connection(mut tcp_stream: TcpStream) {
loop {
let mut buffer = [0; 1028];
Expand Down

0 comments on commit e79f5ed

Please sign in to comment.