From 8082e5d00078a175d0dfe847c6796f59cbe89664 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 20 Feb 2022 18:53:43 -0500 Subject: [PATCH] Read frame. --- src/mpvctl/mpv_framed.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/mpvctl/mpv_framed.rs b/src/mpvctl/mpv_framed.rs index 757009a..9cb5de7 100644 --- a/src/mpvctl/mpv_framed.rs +++ b/src/mpvctl/mpv_framed.rs @@ -18,8 +18,19 @@ impl MpvFramed { pub async fn read_frame( &mut self, ) -> Result, Box> { - // - todo!() + loop { + if let Some(frame) = self.parse_frame()? { + return Ok(Some(frame)); + } + + if 0 == self.socket_read.read_buf(&mut self.buffer).await? { + if self.buffer.is_empty() { + return Ok(None); + } else { + return Err("connection reset by peer".into()); + } + } + } } fn parse_frame(&mut self) -> Result, Box> {