This commit is contained in:
nora 2023-03-07 15:47:19 +01:00
parent e1ebd97c91
commit c4644d42c3
2 changed files with 62 additions and 332 deletions

View file

@ -1,18 +1,17 @@
use std::error::Error as StdError;
#[cfg(feature = "tcp")]
use std::net::{SocketAddr, TcpListener as StdTcpListener};
use pin_project_lite::pin_project;
use tokio::io::{AsyncRead, AsyncWrite};
use self::new_svc::NewSvcTask;
use super::accept::Accept;
use super::conn::Http as Http_;
#[cfg(all(feature = "tcp"))]
use super::tcp::AddrIncoming;
use crate::body::{Body, HttpBody};
use crate::common::exec::Exec;
use crate::common::exec::{ConnStreamExec, NewSvcExec};
use crate::common::{task, Future, Pin, Poll, Unpin};
use super::conn::{Http as Http_, UpgradeableConnection};
use crate::service::{HttpService, MakeServiceRef};
use self::new_svc::NewSvcTask;
use pin_project_lite::pin_project;
use std::error::Error as StdError;
#[cfg(feature = "tcp")]
use tokio::io::{AsyncRead, AsyncWrite};
pin_project! {
#[doc =
" A listening HTTP server that accepts connections in both HTTP1 and HTTP2 by default."]
@ -21,9 +20,9 @@ pin_project! {
" handlers. It is built using the [`Builder`](Builder), and the future"] #[doc =
" completes when the server has been shutdown. It should be run by an"] #[doc =
" `Executor`."]
pub struct Server < I, S, E = Exec > {
#[pin] incoming : I,
make_service : S,
protocol : Http_ < E >,
@ -38,7 +37,6 @@ pub struct Builder<I, E = Exec> {
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))]
impl<I> Server<I, ()> {
pub fn builder(incoming: I) -> Builder<I> {
loop {}
}
@ -49,72 +47,12 @@ impl<I> Server<I, ()> {
doc(cfg(all(feature = "tcp", any(feature = "http1", feature = "http2"))))
)]
impl Server<AddrIncoming, ()> {
pub fn bind() -> Builder<AddrIncoming> {
loop {}
}
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))]
impl<I, IO, IE, S, E, B> Server<I, S, E>
where
I: Accept<Conn = IO, Error = IE>,
IE: Into<Box<dyn StdError + Send + Sync>>,
IO: AsyncRead + AsyncWrite + Unpin + Send + 'static,
S: MakeServiceRef<IO, Body, ResBody = B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: HttpBody + 'static,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
E: ConnStreamExec<<S::Service as HttpService<Body>>::Future, B>,
{
fn poll_next_(
self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
) -> Poll<Option<crate::Result<Connecting<IO, S::Future, E>>>> {
loop {}
}
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))]
impl<I, IO, IE, S, B, E> Future for Server<I, S, E>
where
@ -131,12 +69,8 @@ where
type Output = crate::Result<()>;
fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
loop {
if let Some(connecting) = ready!(self.as_mut().poll_next_(cx) ?) {
let fut = NewSvcTask::new(connecting, NoopWatcher);
self.as_mut().project().protocol.exec.execute_new_svc(fut);
} else {
loop {}
}
let fut = NewSvcTask::new(NoopWatcher);
self.as_mut().project().protocol.exec.execute_new_svc(fut);
}
}
}
@ -148,7 +82,6 @@ impl<I, E> Builder<I, E> {
loop {}
}
pub fn serve<S, B>(self, _: S) -> Server<I, S>
where
I: Accept,
@ -174,38 +107,38 @@ where
}
}
pub(crate) mod new_svc {
use std::error::Error as StdError;
use tokio::io::{AsyncRead, AsyncWrite};
use super::{Connecting, Watcher};
use crate::body::{Body, HttpBody};
use crate::common::exec::ConnStreamExec;
use crate::common::{task, Future, Pin, Poll, Unpin};
use crate::service::HttpService;
use pin_project_lite::pin_project;
use std::error::Error as StdError;
use tokio::io::{AsyncRead, AsyncWrite};
pin_project! {
#[allow(missing_debug_implementations)]
#[allow(missing_debug_implementations)]
pub struct NewSvcTask < I, N, S, E, W : Watcher < I, S, E >> {
#[pin]
#[pin]
state : State <I, S, E, W >,
a: (N)
}
}
pin_project! {
#[project = StateProj]
pub (super) enum State <I, S, E, W : Watcher < I, S, E >> {
Connecting { a: (I, S, W, E), },
Connected { #[pin] future : W::Future, },
}
}
impl<I, N, S: HttpService<Body>, E, W: Watcher<I, S, E>> NewSvcTask<I, N, S, E, W> {
pub(super) fn new(connecting: Connecting<I, N, E>, watcher: W) -> Self {
pub(super) fn new(watcher: W) -> Self {
loop {}
}
}
@ -230,7 +163,13 @@ pin_project! {
#[doc = " A future building a new `Service` to a `Connection`."] #[doc = ""] #[doc =
" Wraps the future returned from `MakeService` into one that returns"] #[doc =
" a `Connection`."] #[must_use = "futures do nothing unless polled"] #[derive(Debug)]
#[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))] pub struct
Connecting < I, F, E = Exec > { #[pin] future : F, io : Option < I >, protocol :
Http_ < E >, }
#[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))]
pub struct Connecting < F, E = Exec > {
#[pin] future : F,
protocol :
Http_ < E >,
}
}