Skip to content

Commit

Permalink
Add comments to ipc loop
Browse files Browse the repository at this point in the history
  • Loading branch information
newtoallofthis123 committed Sep 9, 2024
1 parent efe6c01 commit 53fa2cd
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions swhks/src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,27 @@ pub fn server_loop(sock_file_path: &str) -> std::io::Result<()> {
let mut prev_hash = calculate_hash(String::new());

let listener = UnixListener::bind(sock_file_path)?;
// Init a buffer to read the incoming message
let mut buff = [0; 1];
log::debug!("Listening for incoming connections...");

for stream in listener.incoming() {
match stream {
Ok(mut stream) => {
println!("Connection established!");
stream.read_exact(&mut buff)?;
println!("Received: {:?}", buff);
// If the buffer is [1] then it is a VERIFY message
// the hash of the environment variables is sent back to the client
// then the stream is flushed and the loop continues
if buff == [1] {
log::debug!("Received VERIFY message from swhkd");
let _ = stream.write_all(prev_hash.to_string().as_bytes());
log::debug!("Sent hash to swhkd");
stream.flush()?;
continue;
}
// If the buffer is [2] then it is a GET message
// the environment variables are sent back to the client
// then the stream is flushed and the loop continues
if buff == [2] {
log::debug!("Received GET message from swhkd");
let env = get_env().unwrap();
Expand Down

0 comments on commit 53fa2cd

Please sign in to comment.