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+ ) ) ]
25use std:: time:: Duration ;
36use std:: { fmt, sync:: Arc } ;
47use std:: { pin:: Pin , time:: Instant } ;
@@ -13,46 +16,19 @@ pub(crate) enum Time {
1316 Empty ,
1417}
1518
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+
1626impl fmt:: Debug for Time {
1727 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1828 f. debug_struct ( "Time" ) . finish ( )
1929 }
2030}
2131
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-
5632impl Time {
5733 #[ cfg( all( any( feature = "client" , feature = "server" ) , feature = "http2" ) ) ]
5834 pub ( crate ) fn sleep ( & self , duration : Duration ) -> Pin < Box < dyn Sleep > > {
@@ -82,4 +58,22 @@ impl Time {
8258 Time :: Timer ( ref t) => t. reset ( sleep, new_deadline) ,
8359 }
8460 }
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+ }
8579}
0 commit comments