-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
37 lines (29 loc) · 892 Bytes
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#[macro_use]
extern crate log;
mod config;
mod socket;
use tokio::net::TcpListener;
#[tokio::main]
async fn main() {
let listener = TcpListener::bind("0.0.0.0:8076")
.await
.expect("failed to bind");
let (shutdown, rx) = tokio::sync::broadcast::channel(1);
let mut shutting_down = shutdown.subscribe();
tokio::spawn(async move {
tokio::signal::ctrl_c().await.expect("failed to await ctrl-c");
let _ = shutdown.send(true);
});
loop {
tokio::select! {
socket = listener.accept() => match socket {
Ok((stream, local_ip)) => {
match socket::accept(stream).await {
}
},
Err(err) => error!("Couldn't accept client: {err}")
},
_ = shutting_down.recv() => {}
}
}
}