1
- #[ cfg( all( any( feature = "client" , feature = "server" ) , feature = "http2" ) ) ]
1
+ #[ cfg( any(
2
+ all( any( feature = "client" , feature = "server" ) , feature = "http2" ) ,
3
+ all( feature = "server" , feature = "http1" ) ,
4
+ ) ) ]
2
5
use std:: time:: Duration ;
3
6
use std:: { fmt, sync:: Arc } ;
4
7
use std:: { pin:: Pin , time:: Instant } ;
@@ -13,46 +16,19 @@ pub(crate) enum Time {
13
16
Empty ,
14
17
}
15
18
19
+ #[ cfg( all( feature = "server" , feature = "http1" ) ) ]
20
+ #[ derive( Clone , Copy , Debug ) ]
21
+ pub ( crate ) enum Dur {
22
+ Default ( Option < Duration > ) ,
23
+ Configured ( Option < Duration > ) ,
24
+ }
25
+
16
26
impl fmt:: Debug for Time {
17
27
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
18
28
f. debug_struct ( "Time" ) . finish ( )
19
29
}
20
30
}
21
31
22
- /*
23
- pub(crate) fn timeout<F>(tim: Tim, future: F, duration: Duration) -> HyperTimeout<F> {
24
- HyperTimeout { sleep: tim.sleep(duration), future: future }
25
- }
26
-
27
- pin_project_lite::pin_project! {
28
- pub(crate) struct HyperTimeout<F> {
29
- sleep: Box<dyn Sleep>,
30
- #[pin]
31
- future: F
32
- }
33
- }
34
-
35
- pub(crate) struct Timeout;
36
-
37
- impl<F> Future for HyperTimeout<F> where F: Future {
38
-
39
- type Output = Result<F::Output, Timeout>;
40
-
41
- fn poll(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Self::Output>{
42
- let mut this = self.project();
43
- if let Poll::Ready(v) = this.future.poll(ctx) {
44
- return Poll::Ready(Ok(v));
45
- }
46
-
47
- if let Poll::Ready(_) = Pin::new(&mut this.sleep).poll(ctx) {
48
- return Poll::Ready(Err(Timeout));
49
- }
50
-
51
- return Poll::Pending;
52
- }
53
- }
54
- */
55
-
56
32
impl Time {
57
33
#[ cfg( all( any( feature = "client" , feature = "server" ) , feature = "http2" ) ) ]
58
34
pub ( crate ) fn sleep ( & self , duration : Duration ) -> Pin < Box < dyn Sleep > > {
@@ -82,4 +58,22 @@ impl Time {
82
58
Time :: Timer ( ref t) => t. reset ( sleep, new_deadline) ,
83
59
}
84
60
}
61
+
62
+ #[ cfg( all( feature = "server" , feature = "http1" ) ) ]
63
+ pub ( crate ) fn check ( & self , dur : Dur , name : & ' static str ) -> Option < Duration > {
64
+ match dur {
65
+ Dur :: Default ( Some ( dur) ) => match self {
66
+ Time :: Empty => {
67
+ warn ! ( "timeout `{}` has default, but no timer set" , name, ) ;
68
+ None
69
+ }
70
+ Time :: Timer ( ..) => Some ( dur) ,
71
+ } ,
72
+ Dur :: Configured ( Some ( dur) ) => match self {
73
+ Time :: Empty => panic ! ( "timeout `{}` set, but no timer set" , name, ) ,
74
+ Time :: Timer ( ..) => Some ( dur) ,
75
+ } ,
76
+ Dur :: Default ( None ) | Dur :: Configured ( None ) => None ,
77
+ }
78
+ }
85
79
}
0 commit comments