Created
April 5, 2019 01:41
-
-
Save david415/e3966d18db55c193c418059bca71af5e to your computer and use it in GitHub Desktop.
rust server listen on unix domain socket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::thread; | |
use std::os::unix::net::{UnixStream, UnixListener}; | |
fn handle_client(stream: UnixStream) { | |
// ... | |
} | |
fn main () { | |
let listener = UnixListener::bind("my.socket").unwrap(); | |
// accept connections and process them, spawning a new thread for each one | |
for stream in listener.incoming() { | |
match stream { | |
Ok(stream) => { | |
/* connection succeeded */ | |
thread::spawn(|| handle_client(stream)); | |
} | |
Err(err) => { | |
/* connection failed */ | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment