blob: 350be4fab5c7157a9df1230daf1c607519030ca2 (
plain)
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
|
use crate::interface::generic::generic_handle_connection;
use crate::CLIENT_ID_COUNTER;
use karlcommon::interfaces::unix_path;
use log::{info, warn};
use std::os::unix::net::UnixListener;
use std::thread;
pub fn run() {
if unix_path().exists() {
info!("remove old socket");
std::fs::remove_file(unix_path()).unwrap();
}
let listener = UnixListener::bind(unix_path()).unwrap();
info!("listening.");
loop {
let (stream, addr) = listener.accept().unwrap();
let id = CLIENT_ID_COUNTER.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
thread::spawn(move || {
info!("client connected: {:?}", addr);
if let Err(err) = generic_handle_connection(id, stream.try_clone().unwrap(), stream) {
warn!("client dropped: {:?} ({})", addr, err);
} else {
info!("client dropped: {:?}", addr);
}
});
}
}
|