1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-28 01:52:57 +01:00

remove ka timer from h2 dispatcher (#2057)

This commit is contained in:
fakeshadow 2021-03-08 12:00:20 -08:00 committed by GitHub
parent 5b4105e1e6
commit 5e81105317
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 75 deletions

View File

@ -2,7 +2,6 @@ use std::task::{Context, Poll};
use std::{cmp, future::Future, marker::PhantomData, net, pin::Pin, rc::Rc}; use std::{cmp, future::Future, marker::PhantomData, net, pin::Pin, rc::Rc};
use actix_codec::{AsyncRead, AsyncWrite}; use actix_codec::{AsyncRead, AsyncWrite};
use actix_rt::time::{Instant, Sleep};
use actix_service::Service; use actix_service::Service;
use bytes::{Bytes, BytesMut}; use bytes::{Bytes, BytesMut};
use futures_core::ready; use futures_core::ready;
@ -36,8 +35,6 @@ where
on_connect_data: OnConnectData, on_connect_data: OnConnectData,
config: ServiceConfig, config: ServiceConfig,
peer_addr: Option<net::SocketAddr>, peer_addr: Option<net::SocketAddr>,
ka_expire: Instant,
ka_timer: Option<Sleep>,
_phantom: PhantomData<B>, _phantom: PhantomData<B>,
} }
@ -54,33 +51,14 @@ where
connection: Connection<T, Bytes>, connection: Connection<T, Bytes>,
on_connect_data: OnConnectData, on_connect_data: OnConnectData,
config: ServiceConfig, config: ServiceConfig,
timeout: Option<Sleep>,
peer_addr: Option<net::SocketAddr>, peer_addr: Option<net::SocketAddr>,
) -> Self { ) -> Self {
// let keepalive = config.keep_alive_enabled();
// let flags = if keepalive {
// Flags::KEEPALIVE | Flags::KEEPALIVE_ENABLED
// } else {
// Flags::empty()
// };
// keep-alive timer
let (ka_expire, ka_timer) = if let Some(delay) = timeout {
(delay.deadline(), Some(delay))
} else if let Some(delay) = config.keep_alive_timer() {
(delay.deadline(), Some(delay))
} else {
(config.now(), None)
};
Dispatcher { Dispatcher {
flow, flow,
config, config,
peer_addr, peer_addr,
connection, connection,
on_connect_data, on_connect_data,
ka_expire,
ka_timer,
_phantom: PhantomData, _phantom: PhantomData,
} }
} }
@ -108,13 +86,6 @@ where
Some(Err(err)) => return Poll::Ready(Err(err.into())), Some(Err(err)) => return Poll::Ready(Err(err.into())),
Some(Ok((req, res))) => { Some(Ok((req, res))) => {
// update keep-alive expire
if this.ka_timer.is_some() {
if let Some(expire) = this.config.keep_alive_expire() {
this.ka_expire = expire;
}
}
let (parts, body) = req.into_parts(); let (parts, body) = req.into_parts();
let pl = crate::h2::Payload::new(body); let pl = crate::h2::Payload::new(body);
let pl = Payload::<crate::payload::PayloadStream>::H2(pl); let pl = Payload::<crate::payload::PayloadStream>::H2(pl);
@ -130,7 +101,7 @@ where
// merge on_connect_ext data into request extensions // merge on_connect_ext data into request extensions
this.on_connect_data.merge_into(&mut req); this.on_connect_data.merge_into(&mut req);
let svc = ServiceResponse::<S::Future, S::Response, S::Error, B> { let svc = ServiceResponse {
state: ServiceResponseState::ServiceCall( state: ServiceResponseState::ServiceCall(
this.flow.service.call(req), this.flow.service.call(req),
Some(res), Some(res),
@ -311,11 +282,9 @@ where
} }
ServiceResponseStateProj::SendPayload(ref mut stream, ref mut body) => { ServiceResponseStateProj::SendPayload(ref mut stream, ref mut body) => {
loop {
loop { loop {
match this.buffer { match this.buffer {
Some(ref mut buffer) => { Some(ref mut buffer) => match ready!(stream.poll_capacity(cx)) {
match ready!(stream.poll_capacity(cx)) {
None => return Poll::Ready(()), None => return Poll::Ready(()),
Some(Ok(cap)) => { Some(Ok(cap)) => {
@ -337,23 +306,19 @@ where
warn!("{:?}", e); warn!("{:?}", e);
return Poll::Ready(()); return Poll::Ready(());
} }
} },
}
None => match ready!(body.as_mut().poll_next(cx)) { None => match ready!(body.as_mut().poll_next(cx)) {
None => { None => {
if let Err(e) = stream.send_data(Bytes::new(), true) if let Err(e) = stream.send_data(Bytes::new(), true) {
{
warn!("{:?}", e); warn!("{:?}", e);
} }
return Poll::Ready(()); return Poll::Ready(());
} }
Some(Ok(chunk)) => { Some(Ok(chunk)) => {
stream.reserve_capacity(cmp::min( stream
chunk.len(), .reserve_capacity(cmp::min(chunk.len(), CHUNK_SIZE));
CHUNK_SIZE,
));
*this.buffer = Some(chunk); *this.buffer = Some(chunk);
} }
@ -367,5 +332,4 @@ where
} }
} }
} }
}
} }

View File

@ -368,7 +368,6 @@ where
conn, conn,
on_connect_data, on_connect_data,
config.take().unwrap(), config.take().unwrap(),
None,
*peer_addr, *peer_addr,
)); ));
self.poll(cx) self.poll(cx)

View File

@ -658,7 +658,6 @@ where
conn, conn,
on_connect_data, on_connect_data,
cfg, cfg,
None,
peer_addr, peer_addr,
))); )));
self.poll(cx) self.poll(cx)