remove boxed future from h1 dispatcher

This commit is contained in:
fakeshadow 2020-12-17 20:25:12 +08:00
parent 2a5215c1d6
commit f4c5f79b56
1 changed files with 10 additions and 34 deletions

View File

@ -124,8 +124,8 @@ where
B: MessageBody, B: MessageBody,
{ {
None, None,
ExpectCall(Pin<Box<X::Future>>), ExpectCall(#[pin] X::Future),
ServiceCall(Pin<Box<S::Future>>), ServiceCall(#[pin] S::Future),
SendPayload(#[pin] ResponseBody<B>), SendPayload(#[pin] ResponseBody<B>),
} }
@ -382,12 +382,11 @@ where
} }
None => None, None => None,
}, },
StateProj::ExpectCall(fut) => match fut.as_mut().poll(cx) { StateProj::ExpectCall(fut) => match fut.poll(cx) {
Poll::Ready(Ok(req)) => { Poll::Ready(Ok(req)) => {
self.as_mut().send_continue(); self.as_mut().send_continue();
this = self.as_mut().project(); this = self.as_mut().project();
this.state this.state.set(State::ServiceCall(this.service.call(req)));
.set(State::ServiceCall(Box::pin(this.service.call(req))));
continue; continue;
} }
Poll::Ready(Err(e)) => { Poll::Ready(Err(e)) => {
@ -397,7 +396,7 @@ where
} }
Poll::Pending => None, Poll::Pending => None,
}, },
StateProj::ServiceCall(fut) => match fut.as_mut().poll(cx) { StateProj::ServiceCall(fut) => match fut.poll(cx) {
Poll::Ready(Ok(res)) => { Poll::Ready(Ok(res)) => {
let (res, body) = res.into().replace_body(()); let (res, body) = res.into().replace_body(());
let state = self.as_mut().send_response(res, body)?; let state = self.as_mut().send_response(res, body)?;
@ -473,42 +472,19 @@ where
fn handle_request( fn handle_request(
mut self: Pin<&mut Self>, mut self: Pin<&mut Self>,
req: Request, req: Request,
cx: &mut Context<'_>, _: &mut Context<'_>,
) -> Result<State<S, B, X>, DispatchError> { ) -> Result<State<S, B, X>, DispatchError> {
// Handle `EXPECT: 100-Continue` header // Handle `EXPECT: 100-Continue` header
let req = if req.head().expect() { let req = if req.head().expect() {
let mut task = Box::pin(self.as_mut().project().expect.call(req)); let task = self.as_mut().project().expect.call(req);
match task.as_mut().poll(cx) { return Ok(State::ExpectCall(task));
Poll::Ready(Ok(req)) => {
self.as_mut().send_continue();
req
}
Poll::Pending => return Ok(State::ExpectCall(task)),
Poll::Ready(Err(e)) => {
let e = e.into();
let res: Response = e.into();
let (res, body) = res.replace_body(());
return self.send_response(res, body.into_body());
}
}
} else { } else {
req req
}; };
// Call service // Call service
let mut task = Box::pin(self.as_mut().project().service.call(req)); let task = self.as_mut().project().service.call(req);
match task.as_mut().poll(cx) { Ok(State::ServiceCall(task))
Poll::Ready(Ok(res)) => {
let (res, body) = res.into().replace_body(());
self.send_response(res, body)
}
Poll::Pending => Ok(State::ServiceCall(task)),
Poll::Ready(Err(e)) => {
let res: Response = e.into().into();
let (res, body) = res.replace_body(());
self.send_response(res, body.into_body())
}
}
} }
/// Process one incoming requests /// Process one incoming requests