-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.rs
More file actions
37 lines (32 loc) · 957 Bytes
/
main.rs
File metadata and controls
37 lines (32 loc) · 957 Bytes
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
pub mod connection;
pub mod group;
pub mod group_table;
use connection::serve;
use async_std::net::TcpListener;
use async_std::prelude::*;
use async_std::task;
use std::sync::Arc;
fn main() -> anyhow::Result<()> {
let address = std::env::args().nth(1).expect(
"Usage: server
ADDRESS",
);
let chat_group_table = Arc::new(group_table::GroupTable::new());
async_std::task::block_on(async {
let listener = TcpListener::bind(address).await?;
let mut new_connections = listener.incoming();
while let Some(socket_result) = new_connections.next().await {
let socket = socket_result?;
let groups = chat_group_table.clone();
task::spawn(async {
log_error(serve(socket, groups).await);
});
}
Ok(())
})
}
fn log_error(result: anyhow::Result<()>) {
if let Err(error) = result {
eprintln!("Error: {}", error);
}
}