aboutsummaryrefslogtreecommitdiff
path: root/karld/src/interface/unix.rs
blob: 9989b0f3560f15060d163e35b22db0412cb8378a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use crate::interface::generic;
use karlcommon::interfaces::unix_path;
use log::info;
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();
    }
    info!("binding to socket");
    let listener = UnixListener::bind(unix_path()).unwrap();
    info!("listening.");

    loop {
        let (stream, _addr) = listener.accept().unwrap();
        thread::spawn(move || {
            generic::handle_connection(generic::stream, (stream.try_clone().unwrap(), stream))
        });
    }
}