Skip to content

Commit

Permalink
fix : read from unix socket
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxtho8 committed Mar 31, 2023
1 parent ce272e0 commit 788acb7
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
Expand Down

0 comments on commit 788acb7

Please sign in to comment.