summaryrefslogtreecommitdiff
path: root/vendor/hyper/src/common/time.rs
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-02 18:36:06 -0600
committermo khan <mo@mokhan.ca>2025-07-02 18:36:06 -0600
commit8cdfa445d6629ffef4cb84967ff7017654045bc2 (patch)
tree22f0b0907c024c78d26a731e2e1f5219407d8102 /vendor/hyper/src/common/time.rs
parent4351c74c7c5f97156bc94d3a8549b9940ac80e3f (diff)
chore: add vendor directory
Diffstat (limited to 'vendor/hyper/src/common/time.rs')
-rw-r--r--vendor/hyper/src/common/time.rs79
1 files changed, 79 insertions, 0 deletions
diff --git a/vendor/hyper/src/common/time.rs b/vendor/hyper/src/common/time.rs
new file mode 100644
index 00000000..a8d3cc9c
--- /dev/null
+++ b/vendor/hyper/src/common/time.rs
@@ -0,0 +1,79 @@
+#[cfg(any(
+ all(any(feature = "client", feature = "server"), feature = "http2"),
+ all(feature = "server", feature = "http1"),
+))]
+use std::time::Duration;
+use std::{fmt, sync::Arc};
+use std::{pin::Pin, time::Instant};
+
+use crate::rt::Sleep;
+use crate::rt::Timer;
+
+/// A user-provided timer to time background tasks.
+#[derive(Clone)]
+pub(crate) enum Time {
+ Timer(Arc<dyn Timer + Send + Sync>),
+ Empty,
+}
+
+#[cfg(all(feature = "server", feature = "http1"))]
+#[derive(Clone, Copy, Debug)]
+pub(crate) enum Dur {
+ Default(Option<Duration>),
+ Configured(Option<Duration>),
+}
+
+impl fmt::Debug for Time {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("Time").finish()
+ }
+}
+
+impl Time {
+ #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))]
+ pub(crate) fn sleep(&self, duration: Duration) -> Pin<Box<dyn Sleep>> {
+ match *self {
+ Time::Empty => {
+ panic!("You must supply a timer.")
+ }
+ Time::Timer(ref t) => t.sleep(duration),
+ }
+ }
+
+ #[cfg(feature = "http1")]
+ pub(crate) fn sleep_until(&self, deadline: Instant) -> Pin<Box<dyn Sleep>> {
+ match *self {
+ Time::Empty => {
+ panic!("You must supply a timer.")
+ }
+ Time::Timer(ref t) => t.sleep_until(deadline),
+ }
+ }
+
+ pub(crate) fn reset(&self, sleep: &mut Pin<Box<dyn Sleep>>, new_deadline: Instant) {
+ match *self {
+ Time::Empty => {
+ panic!("You must supply a timer.")
+ }
+ Time::Timer(ref t) => t.reset(sleep, new_deadline),
+ }
+ }
+
+ #[cfg(all(feature = "server", feature = "http1"))]
+ pub(crate) fn check(&self, dur: Dur, name: &'static str) -> Option<Duration> {
+ match dur {
+ Dur::Default(Some(dur)) => match self {
+ Time::Empty => {
+ warn!("timeout `{}` has default, but no timer set", name,);
+ None
+ }
+ Time::Timer(..) => Some(dur),
+ },
+ Dur::Configured(Some(dur)) => match self {
+ Time::Empty => panic!("timeout `{}` set, but no timer set", name,),
+ Time::Timer(..) => Some(dur),
+ },
+ Dur::Default(None) | Dur::Configured(None) => None,
+ }
+ }
+}