Created
May 7, 2020 10:23
-
-
Save majecty/1d0e25fd21b7de5b70fa343f98d99a96 to your computer and use it in GitHub Desktop.
This file contains 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::net::Shutdown; | |
use std::os::unix::net::UnixDatagram; | |
use std::{sync::Arc, thread}; | |
fn main() -> std::io::Result<()> { | |
let sock = Arc::new(UnixDatagram::bind("./my-unix-socket")?); | |
let mut buf = vec![0; 10]; | |
let builder = thread::Builder::new() | |
.name("foo".into()) | |
.stack_size(32 * 1024); | |
let sock2 = sock.clone(); | |
let handler = builder | |
.spawn(move || { | |
std::thread::sleep(std::time::Duration::from_secs(3)); | |
sock2.shutdown(Shutdown::Both); | |
}) | |
.unwrap(); | |
sock.recv(buf.as_mut_slice()).expect("recv function failed"); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment