Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
node: Read with timeout from worker channel
Alexis Sellier committed 3 years ago
commit 7037b52474a9d38293c04bb5580a37dd112bdbf9
parent d758c4f203c205c08fc822181d6f4df9d1320607
1 file changed +6 -2
modified radicle-node/src/worker/channels.rs
@@ -131,7 +131,7 @@ impl Read for ChannelReader<Vec<u8>> {
            return Ok(read);
        }

-
        match self.receiver.recv() {
+
        match self.receiver.recv_timeout(self.timeout) {
            Ok(ChannelEvent::Data(data)) => {
                self.buffer = io::Cursor::new(data);
                self.buffer.read(buf)
@@ -139,7 +139,11 @@ impl Read for ChannelReader<Vec<u8>> {
            Ok(ChannelEvent::Eof) => Err(io::ErrorKind::UnexpectedEof.into()),
            Ok(ChannelEvent::Close) => Err(io::ErrorKind::ConnectionReset.into()),

-
            Err(_) => Err(io::Error::new(
+
            Err(chan::RecvTimeoutError::Timeout) => Err(io::Error::new(
+
                io::ErrorKind::TimedOut,
+
                "error reading from stream: channel timed out",
+
            )),
+
            Err(chan::RecvTimeoutError::Disconnected) => Err(io::Error::new(
                io::ErrorKind::BrokenPipe,
                "error reading from stream: channel is disconnected",
            )),