1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-27 03:51:10 +00:00

diesable client timeout for tcp stream acceptor

This commit is contained in:
Nikolay Kim 2018-09-27 19:34:07 -07:00
parent 85445ea809
commit 3173c9fa83
2 changed files with 26 additions and 8 deletions

View file

@ -18,6 +18,7 @@ pub(crate) trait ServiceProvider {
) -> Server;
}
/// Utility type that builds complete http pipeline
pub struct HttpServiceBuilder<F, H, A, P>
where
F: Fn() -> H + Send + Clone,
@ -25,6 +26,7 @@ where
factory: F,
acceptor: A,
pipeline: P,
no_client_timer: bool,
}
impl<F, H, A, P> HttpServiceBuilder<F, H, A, P>
@ -40,9 +42,15 @@ where
factory,
pipeline,
acceptor,
no_client_timer: false,
}
}
pub(crate) fn no_client_timer(mut self) -> Self {
self.no_client_timer = true;
self
}
/// Use different acceptor factory
pub fn acceptor<A1>(self, acceptor: A1) -> HttpServiceBuilder<F, H, A1, P>
where
@ -52,6 +60,7 @@ where
acceptor,
pipeline: self.pipeline,
factory: self.factory.clone(),
no_client_timer: self.no_client_timer,
}
}
@ -64,6 +73,7 @@ where
pipeline,
acceptor: self.acceptor,
factory: self.factory.clone(),
no_client_timer: self.no_client_timer,
}
}
@ -71,6 +81,11 @@ where
&self, host: Option<String>, addr: net::SocketAddr, keep_alive: KeepAlive,
client_timeout: usize,
) -> impl ServiceFactory {
let timeout = if self.no_client_timer {
0
} else {
client_timeout
};
let factory = self.factory.clone();
let pipeline = self.pipeline.clone();
let acceptor = self.acceptor.clone();
@ -79,11 +94,11 @@ where
let settings = WorkerSettings::new(
app,
keep_alive,
client_timeout as u64,
timeout as u64,
ServerSettings::new(Some(addr), &host, false),
);
if client_timeout == 0 {
if timeout == 0 {
Either::A(TcpAcceptor::new(
settings.clone(),
acceptor.create().and_then(pipeline.create(settings)),
@ -91,7 +106,7 @@ where
} else {
Either::B(TcpAcceptor::new(
settings.clone(),
AcceptorTimeout::new(client_timeout, acceptor.create())
AcceptorTimeout::new(timeout, acceptor.create())
.map_err(|_| ())
.and_then(pipeline.create(settings)),
))
@ -112,6 +127,7 @@ where
factory: self.factory.clone(),
acceptor: self.acceptor.clone(),
pipeline: self.pipeline.clone(),
no_client_timer: self.no_client_timer,
}
}
}

View file

@ -219,11 +219,13 @@ where
lst,
addr,
scheme: "http",
handler: Box::new(HttpServiceBuilder::new(
handler: Box::new(
HttpServiceBuilder::new(
self.factory.clone(),
DefaultAcceptor,
DefaultPipelineFactory::new(),
)),
).no_client_timer(),
),
});
self