Skip to content

Commit 722eba1

Browse files
authored
Merge pull request #24 from ionut-arm/timeout
Add methods for modifying timeout of IPC handlers
2 parents 2b27aa9 + a3e8667 commit 722eba1

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

src/core/ipc_handler/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! Types implementing an abstraction over IPC channels
44
use crate::error::Result;
55
use std::io::{Read, Write};
6+
use std::time::Duration;
67

78
pub mod unix_socket;
89

@@ -18,4 +19,7 @@ impl<T: Read + Write> ReadWrite for T {}
1819
pub trait Connect {
1920
/// Connect to underlying IPC and return a readable and writeable stream
2021
fn connect(&self) -> Result<Box<dyn ReadWrite>>;
22+
23+
/// Set timeout for all produced streams.
24+
fn set_timeout(&mut self, timeout: Option<Duration>);
2125
}

src/core/ipc_handler/unix_socket.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ impl Connect for Handler {
3232

3333
Ok(Box::from(stream))
3434
}
35+
36+
fn set_timeout(&mut self, timeout: Option<Duration>) {
37+
self.timeout = timeout;
38+
}
3539
}
3640

3741
impl Handler {

src/core/request_client.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use super::ipc_handler::{unix_socket, Connect};
55
use crate::error::{ClientErrorKind, Result};
66
use derivative::Derivative;
77
use parsec_interface::requests::{Request, Response};
8+
use std::time::Duration;
89

910
const DEFAULT_MAX_BODY_SIZE: usize = usize::max_value();
1011

@@ -65,4 +66,14 @@ impl crate::BasicClient {
6566
pub fn set_ipc_handler(&mut self, ipc_handler: Box<dyn Connect>) {
6667
self.op_client.request_client.ipc_handler = ipc_handler;
6768
}
69+
70+
/// Set the timeout for operations on the IPC stream.
71+
///
72+
/// The value defaults to 1 second.
73+
pub fn set_timeout(&mut self, timeout: Option<Duration>) {
74+
self.op_client
75+
.request_client
76+
.ipc_handler
77+
.set_timeout(timeout);
78+
}
6879
}

src/core/testing/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::error::Result;
88
use mockstream::{FailingMockStream, SyncMockStream};
99
use parsec_interface::requests::ProviderID;
1010
use std::ops::{Deref, DerefMut};
11+
use std::time::Duration;
1112

1213
mod core_tests;
1314

@@ -19,6 +20,8 @@ impl Connect for MockIpc {
1920
fn connect(&self) -> Result<Box<dyn ReadWrite>> {
2021
Ok(Box::from(self.0.clone()))
2122
}
23+
24+
fn set_timeout(&mut self, _timeout: Option<Duration>) {}
2225
}
2326

2427
struct FailingMockIpc(FailingMockStream);
@@ -27,6 +30,8 @@ impl Connect for FailingMockIpc {
2730
fn connect(&self) -> Result<Box<dyn ReadWrite>> {
2831
Ok(Box::from(self.0.clone()))
2932
}
33+
34+
fn set_timeout(&mut self, _timeout: Option<Duration>) {}
3035
}
3136

3237
struct TestBasicClient {

0 commit comments

Comments
 (0)