Skip to content

Commit

Permalink
support timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Dec 8, 2023
1 parent 1a23827 commit bde85f5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ members = [

[package]
name = "mco-rpc"
version = "0.1.7"
version = "0.1.8"
authors = ["zxj <zhuxiujia@qq.com>"]
license = "MIT"
documentation = "https://docs.rs/mco-rpc"
Expand Down
8 changes: 2 additions & 6 deletions src/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::io::{BufReader, Write};
use std::sync::atomic::{AtomicU64, Ordering};
use std::time::Duration;
use log::{error, debug};
use mco::{err};
use mco::net::TcpStream;
use mco::std::errors::Result;
use mco::std::sync::SyncHashMap;
Expand Down Expand Up @@ -58,7 +57,8 @@ impl ClientStub {
debug!("request id = {}", id);
let data = req_buf.finish(id);
stream.write_all(&data)?;
let time = std::time::Instant::now();
stream.set_read_timeout(self.timeout.clone().into())?;
stream.set_write_timeout(self.timeout.clone().into())?;
// read the response
loop {
// deserialize the rsp
Expand All @@ -70,10 +70,6 @@ impl ClientStub {
let rsp_data = rsp_frame.decode_rsp().map_err(|e| Error::from(e.to_string()))?;
let resp: Resp = codec.decode(rsp_data)?;
return Ok(resp);
} else {
if time.elapsed() > self.timeout {
return Err(err!("rpc call timeout!"));
}
}
}
}
Expand Down

0 comments on commit bde85f5

Please sign in to comment.