Skip to content

Instantly share code, notes, and snippets.

@david415
Created April 5, 2019 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save david415/e3966d18db55c193c418059bca71af5e to your computer and use it in GitHub Desktop.
Save david415/e3966d18db55c193c418059bca71af5e to your computer and use it in GitHub Desktop.
rust server listen on unix domain socket
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