mirror of
https://github.com/actix/actix-web.git
synced 2024-11-18 07:35:36 +00:00
remove ka timer from h2 dispatcher (#2057)
This commit is contained in:
parent
5b4105e1e6
commit
5e81105317
3 changed files with 37 additions and 75 deletions
|
@ -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),
|
||||||
|
@ -312,57 +283,50 @@ 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) => match ready!(stream.poll_capacity(cx)) {
|
||||||
Some(ref mut buffer) => {
|
None => return Poll::Ready(()),
|
||||||
match ready!(stream.poll_capacity(cx)) {
|
|
||||||
None => return Poll::Ready(()),
|
|
||||||
|
|
||||||
Some(Ok(cap)) => {
|
Some(Ok(cap)) => {
|
||||||
let len = buffer.len();
|
let len = buffer.len();
|
||||||
let bytes = buffer.split_to(cmp::min(cap, len));
|
let bytes = buffer.split_to(cmp::min(cap, len));
|
||||||
|
|
||||||
if let Err(e) = stream.send_data(bytes, false) {
|
if let Err(e) = stream.send_data(bytes, false) {
|
||||||
warn!("{:?}", e);
|
warn!("{:?}", e);
|
||||||
return Poll::Ready(());
|
return Poll::Ready(());
|
||||||
} else if !buffer.is_empty() {
|
} else if !buffer.is_empty() {
|
||||||
let cap = cmp::min(buffer.len(), CHUNK_SIZE);
|
let cap = cmp::min(buffer.len(), CHUNK_SIZE);
|
||||||
stream.reserve_capacity(cap);
|
stream.reserve_capacity(cap);
|
||||||
} else {
|
} else {
|
||||||
this.buffer.take();
|
this.buffer.take();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(Err(e)) => {
|
|
||||||
warn!("{:?}", e);
|
|
||||||
return Poll::Ready(());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
None => match ready!(body.as_mut().poll_next(cx)) {
|
Some(Err(e)) => {
|
||||||
None => {
|
warn!("{:?}", e);
|
||||||
if let Err(e) = stream.send_data(Bytes::new(), true)
|
return Poll::Ready(());
|
||||||
{
|
}
|
||||||
warn!("{:?}", e);
|
},
|
||||||
}
|
|
||||||
return Poll::Ready(());
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(Ok(chunk)) => {
|
None => match ready!(body.as_mut().poll_next(cx)) {
|
||||||
stream.reserve_capacity(cmp::min(
|
None => {
|
||||||
chunk.len(),
|
if let Err(e) = stream.send_data(Bytes::new(), true) {
|
||||||
CHUNK_SIZE,
|
warn!("{:?}", e);
|
||||||
));
|
|
||||||
*this.buffer = Some(chunk);
|
|
||||||
}
|
}
|
||||||
|
return Poll::Ready(());
|
||||||
|
}
|
||||||
|
|
||||||
Some(Err(e)) => {
|
Some(Ok(chunk)) => {
|
||||||
error!("Response payload stream error: {:?}", e);
|
stream
|
||||||
return Poll::Ready(());
|
.reserve_capacity(cmp::min(chunk.len(), CHUNK_SIZE));
|
||||||
}
|
*this.buffer = Some(chunk);
|
||||||
},
|
}
|
||||||
}
|
|
||||||
|
Some(Err(e)) => {
|
||||||
|
error!("Response payload stream error: {:?}", e);
|
||||||
|
return Poll::Ready(());
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue