aboutsummaryrefslogtreecommitdiff
path: root/src/call
diff options
context:
space:
mode:
Diffstat (limited to 'src/call')
-rw-r--r--src/call/client.rs2
-rw-r--r--src/call/mod.rs8
-rw-r--r--src/call/server.rs26
3 files changed, 27 insertions, 9 deletions
diff --git a/src/call/client.rs b/src/call/client.rs
index 279e619..d1047bf 100644
--- a/src/call/client.rs
+++ b/src/call/client.rs
@@ -399,7 +399,7 @@ impl<Req> Sink<(Req, WriteFlags)> for StreamingCallSink<Req> {
t.close_f = Some(close_f);
}
- if let Poll::Pending = Pin::new(t.close_f.as_mut().unwrap()).poll(cx)? {
+ if Pin::new(t.close_f.as_mut().unwrap()).poll(cx)?.is_pending() {
// if call is finished, can return early here.
call.check_alive()?;
return Poll::Pending;
diff --git a/src/call/mod.rs b/src/call/mod.rs
index a06e003..7f1582f 100644
--- a/src/call/mod.rs
+++ b/src/call/mod.rs
@@ -33,9 +33,9 @@ impl From<i32> for RpcStatusCode {
}
}
-impl Into<i32> for RpcStatusCode {
- fn into(self) -> i32 {
- self.0
+impl From<RpcStatusCode> for i32 {
+ fn from(code: RpcStatusCode) -> i32 {
+ code.0
}
}
@@ -533,7 +533,7 @@ impl StreamingBase {
if !skip_finish_check {
let mut finished = false;
if let Some(close_f) = &mut self.close_f {
- if let Poll::Ready(_) = Pin::new(close_f).poll(cx)? {
+ if Pin::new(close_f).poll(cx)?.is_ready() {
// Don't return immediately, there may be pending data.
finished = true;
}
diff --git a/src/call/server.rs b/src/call/server.rs
index 875555e..0fed656 100644
--- a/src/call/server.rs
+++ b/src/call/server.rs
@@ -3,6 +3,7 @@
use std::ffi::CStr;
use std::pin::Pin;
use std::sync::Arc;
+use std::time::Duration;
use std::{result, slice};
use crate::grpc_sys::{
@@ -30,8 +31,10 @@ use crate::server::{BoxHandler, RequestCallContext};
use crate::task::{BatchFuture, CallTag, Executor, Kicker};
use crate::CheckResult;
+/// A time point that an rpc or operation should finished before it.
+#[derive(Clone, Copy)]
pub struct Deadline {
- spec: gpr_timespec,
+ pub(crate) spec: gpr_timespec,
}
impl Deadline {
@@ -44,12 +47,27 @@ impl Deadline {
}
}
- pub fn exceeded(&self) -> bool {
+ /// Checks if the deadline is exceeded.
+ pub fn exceeded(self) -> bool {
unsafe {
let now = grpc_sys::gpr_now(gpr_clock_type::GPR_CLOCK_REALTIME);
grpc_sys::gpr_time_cmp(now, self.spec) >= 0
}
}
+
+ pub(crate) fn spec(self) -> gpr_timespec {
+ self.spec
+ }
+}
+
+impl From<Duration> for Deadline {
+ /// Build a deadline from given duration.
+ ///
+ /// The deadline will be `now + duration`.
+ #[inline]
+ fn from(dur: Duration) -> Deadline {
+ Deadline::new(dur.into())
+ }
}
/// Context for accepting a request.
@@ -626,8 +644,8 @@ impl<'a> RpcContext<'a> {
self.ctx.host()
}
- pub fn deadline(&self) -> &Deadline {
- &self.deadline
+ pub fn deadline(&self) -> Deadline {
+ self.deadline
}
/// Get the initial metadata sent by client.