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

View file

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