diff --git a/src/main.rs b/src/main.rs index a09d5f7..041b3e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,16 +50,20 @@ fn main() -> Result<(), Error> { } println!("Socket path: {}", path.to_str().unwrap()); + let unix_listener = UnixListener::bind(path).unwrap(); std::thread::spawn(move || { + // read from socket + let (mut stream, _) = unix_listener.accept().unwrap(); + let mut buffer = [0; 1024]; loop { - let (mut unix_stream, socket_address) = unix_listener.accept().unwrap(); - // print stream - let mut message = String::new(); - unix_stream.read_to_string(&mut message).unwrap(); - - print!("{}.", message); + let n = stream.read(&mut buffer).unwrap(); + if n == 0 { + break; + } + let s = String::from_utf8_lossy(&buffer[0..n]).to_string(); + print!("{}", s); } }); }