Skip to content

Commit

Permalink
feat: add ctrl+c signal
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 committed Apr 13, 2024
1 parent eb9d236 commit afccefc
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/models/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,22 @@ impl Server {
}
};

tokio::spawn(async move {
match tokio::signal::ctrl_c().await {
Ok(_) => {}
Err(e) => {
eprintln!("{}", e.to_string().red());
std::process::exit(1);
}
}
std::process::exit(0);
});

println!(
"Starting server at {}",
format!("Oblivion://{}:{}/", self.host, self.port).bright_cyan()
);
println!("Quit the server by CTRL-BREAK.");
println!("Quit the server by CTRL-BREAK.\n");

while let Ok((stream, peer)) = tcp.accept().await {
let router = self.router.clone();
Expand Down

0 comments on commit afccefc

Please sign in to comment.