Skip to content

Commit

Permalink
Merge pull request #9 from WhyNotHugo/cleanups
Browse files Browse the repository at this point in the history
Misc minor cleanups
  • Loading branch information
Sami Vänttinen authored Jun 2, 2022
2 parents 338735e + 689db2f commit bd10966
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
12 changes: 5 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ fn read_body<T: Read + Write>(length: u32, socket: &mut ProxySocket<T>) {
let stdin = io::stdin();
let mut handle = stdin.lock();

if let Ok(_) = handle.read_exact(&mut buffer) {
if valid_length(length) {
socket.write(&buffer).unwrap();
socket.flush().unwrap();
read_response(socket);
}
if handle.read_exact(&mut buffer).is_ok() && valid_length(length) {
socket.write_all(&buffer).unwrap();
socket.flush().unwrap();
read_response(socket);
}
}

Expand All @@ -52,7 +50,7 @@ fn write_response(buf: &[u8]) {
let mut out = stdout.lock();

out.write_u32::<NativeEndian>(buf.len() as u32).unwrap();
out.write(buf).unwrap();
out.write_all(buf).unwrap();
out.flush().unwrap();
}

Expand Down
9 changes: 4 additions & 5 deletions src/proxy_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ pub fn connect(buffer_size: u32) -> io::Result<ProxySocket<UnixStream>> {
use std::time::Duration;

let socket_name = "org.keepassxc.KeePassXC.BrowserServer";
let socket: String;
if let Ok(dir) = if cfg!(target_os = "macos") {env::var("TMPDIR") } else { env::var("XDG_RUNTIME_DIR") } {
socket = format!("{}/{}", dir, socket_name);
let socket = if let Ok(dir) = if cfg!(target_os = "macos") {env::var("TMPDIR") } else { env::var("XDG_RUNTIME_DIR") } {
format!("{}/{}", dir, socket_name)
} else {
socket = format!("/tmp/{}", socket_name);
}
format!("/tmp/{}", socket_name)
};
let s = UnixStream::connect(socket)?;
socket::setsockopt(s.as_raw_fd(), SndBuf, &(buffer_size as usize)).expect("setsockopt for SndBuf failed");
socket::setsockopt(s.as_raw_fd(), RcvBuf, &(buffer_size as usize)).expect("setsockopt for RcvBuf failed");
Expand Down

0 comments on commit bd10966

Please sign in to comment.