From 3b8aafe1018ed626dbb4c19759195a05be93a1bf Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Sun, 2 Apr 2023 22:32:52 +0300 Subject: small changes --- src/status_cmd.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/status_cmd.rs') diff --git a/src/status_cmd.rs b/src/status_cmd.rs index 58ba877..172bee2 100644 --- a/src/status_cmd.rs +++ b/src/status_cmd.rs @@ -40,8 +40,8 @@ impl StatusCmd { }) } - pub fn read(&mut self) -> Result>> { - match read(self.output.as_raw_fd(), &mut self.buf) { + pub fn receive_blocks(&mut self) -> Result>> { + match read_to_vec(self.output.as_raw_fd(), &mut self.buf) { Ok(0) => bail!("status command exited"), Ok(_n) => (), Err(Errno::EAGAIN) => return Ok(None), @@ -57,7 +57,7 @@ impl StatusCmd { pub fn send_click_event(&mut self, event: &Event) -> Result<()> { if self.protocol.supports_clicks() { - writeln!(self.input, "{}", serde_json::to_string(event).unwrap())?; + writeln!(self.input, "{}", serde_json::to_string(event)?)?; } Ok(()) } @@ -66,7 +66,7 @@ impl StatusCmd { /// Read from a raw file descriptor to the vector. /// /// Appends data at the end of the buffer. Resizes vector as needed. -pub fn read(fd: RawFd, buf: &mut Vec) -> nix::Result { +pub fn read_to_vec(fd: RawFd, buf: &mut Vec) -> nix::Result { if buf.capacity() - buf.len() < 1024 { buf.reserve(buf.capacity().max(1024)); } @@ -79,12 +79,8 @@ pub fn read(fd: RawFd, buf: &mut Vec) -> nix::Result { ) }; - let read = Errno::result(res).map(|r| r as usize)?; - if read > 0 { - unsafe { - buf.set_len(buf.len() + read); - } - } + let read = Errno::result(res)? as usize; + unsafe { buf.set_len(buf.len() + read) }; Ok(read) } -- cgit v1.3.1