提交 e01c4570 authored 作者: Serhij S's avatar Serhij S

timeouts structure

上级 e54d98dc
...@@ -73,12 +73,30 @@ impl CommReader { ...@@ -73,12 +73,30 @@ impl CommReader {
impl DataDeliveryPolicy for CommReader {} impl DataDeliveryPolicy for CommReader {}
pub(crate) struct Timeouts { #[derive(Default, Clone)]
pub struct Timeouts {
pub connect: Duration, pub connect: Duration,
pub read: Duration, pub read: Duration,
pub write: Duration, pub write: Duration,
} }
impl Timeouts {
pub fn new(default: Duration) -> Self {
Self {
connect: default,
read: default,
write: default,
}
}
pub fn none() -> Self {
Self {
connect: Duration::from_secs(0),
read: Duration::from_secs(0),
write: Duration::from_secs(0),
}
}
}
pub type ChatFn = dyn Fn(&mut dyn Stream) -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> pub type ChatFn = dyn Fn(&mut dyn Stream) -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>>
+ Send + Send
+ Sync; + Sync;
...@@ -122,6 +140,11 @@ impl ConnectionOptions { ...@@ -122,6 +140,11 @@ impl ConnectionOptions {
self.chat = Some(Box::new(chat)); self.chat = Some(Box::new(chat));
self self
} }
/// Set timeouts
pub fn timeouts(mut self, timeouts: Timeouts) -> Self {
self.timeouts = timeouts;
self
}
/// Set the connect timeout /// Set the connect timeout
pub fn connect_timeout(mut self, timeout: Duration) -> Self { pub fn connect_timeout(mut self, timeout: Duration) -> Self {
self.timeouts.connect = timeout; self.timeouts.connect = timeout;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论