mirror of
https://github.com/Noratrieb/icefun.git
synced 2026-01-14 21:05:00 +01:00
loop
This commit is contained in:
parent
43b96cd25f
commit
4d90501fee
4 changed files with 35 additions and 21 deletions
|
|
@ -170,10 +170,8 @@ mod upgrades {
|
||||||
#[must_use = "futures do nothing unless polled"]
|
#[must_use = "futures do nothing unless polled"]
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct UpgradeableConnection<T, S, E>
|
pub struct UpgradeableConnection<T, S, E>
|
||||||
where
|
|
||||||
S: HttpService<Body>,
|
|
||||||
{
|
{
|
||||||
pub(super) inner: Connection<T, S, E>,
|
pub(super) inner: (T, S, E),
|
||||||
}
|
}
|
||||||
impl<I, B, S, E> UpgradeableConnection<I, S, E>
|
impl<I, B, S, E> UpgradeableConnection<I, S, E>
|
||||||
where
|
where
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,21 @@ pin_project! {
|
||||||
" `Server` is a `Future` mapping a bound listener with a set of service"] #[doc =
|
" `Server` is a `Future` mapping a bound listener with a set of service"] #[doc =
|
||||||
" handlers. It is built using the [`Builder`](Builder), and the future"] #[doc =
|
" 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 =
|
" 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,
|
" `Executor`."]
|
||||||
make_service : S, protocol : Http_ < E >, }
|
|
||||||
|
pub struct Server < I, S, E = Exec > {
|
||||||
|
|
||||||
|
#[pin] incoming : I,
|
||||||
|
make_service : S,
|
||||||
|
protocol : Http_ < E >,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// A builder for a [`Server`](Server).
|
/// A builder for a [`Server`](Server).
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))]
|
#[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))]
|
||||||
pub struct Builder<I, E = Exec> {
|
pub struct Builder<I, E = Exec> {
|
||||||
incoming: I,
|
incoming: I,
|
||||||
protocol: Http_<E>,
|
protocol: E,
|
||||||
}
|
}
|
||||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))]
|
#[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))]
|
||||||
impl<I> Server<I, ()> {
|
impl<I> Server<I, ()> {
|
||||||
|
|
@ -50,7 +56,7 @@ impl Server<AddrIncoming, ()> {
|
||||||
///
|
///
|
||||||
/// This method will panic if binding to the address fails. For a method
|
/// This method will panic if binding to the address fails. For a method
|
||||||
/// to bind to an address and return a `Result`, see `Server::try_bind`.
|
/// to bind to an address and return a `Result`, see `Server::try_bind`.
|
||||||
pub fn bind(addr: &SocketAddr) -> Builder<AddrIncoming> {
|
pub fn bind() -> Builder<AddrIncoming> {
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -161,15 +167,14 @@ impl<I, E> Builder<I, E> {
|
||||||
pub fn serve<S, B>(self, _: S) -> Server<I, S>
|
pub fn serve<S, B>(self, _: S) -> Server<I, S>
|
||||||
where
|
where
|
||||||
I: Accept,
|
I: Accept,
|
||||||
I::Error: Into<Box<dyn StdError + Send + Sync>>,
|
|
||||||
S: MakeServiceRef<I::Conn, Body, ResBody = B>,
|
S: MakeServiceRef<I::Conn, Body, ResBody = B>,
|
||||||
{
|
{
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub trait Watcher<I, S: HttpService<Body>, E>: Clone {
|
pub trait Watcher<I, S, E>: Clone {
|
||||||
type Future: Future<Output = crate::Result<()>>;
|
type Future;
|
||||||
fn watch(&self, conn: UpgradeableConnection<I, S, E>) -> Self::Future;
|
fn watch(&self) -> Self::Future;
|
||||||
}
|
}
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
|
|
@ -183,7 +188,7 @@ where
|
||||||
<S::ResBody as HttpBody>::Error: Into<Box<dyn StdError + Send + Sync>>,
|
<S::ResBody as HttpBody>::Error: Into<Box<dyn StdError + Send + Sync>>,
|
||||||
{
|
{
|
||||||
type Future = UpgradeableConnection<I, S, E>;
|
type Future = UpgradeableConnection<I, S, E>;
|
||||||
fn watch(&self, conn: UpgradeableConnection<I, S, E>) -> Self::Future {
|
fn watch(&self) -> Self::Future {
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -197,14 +202,26 @@ pub(crate) mod new_svc {
|
||||||
use crate::service::HttpService;
|
use crate::service::HttpService;
|
||||||
use pin_project_lite::pin_project;
|
use pin_project_lite::pin_project;
|
||||||
pin_project! {
|
pin_project! {
|
||||||
#[allow(missing_debug_implementations)] pub struct NewSvcTask < I, N, S :
|
#[allow(missing_debug_implementations)]
|
||||||
HttpService < Body >, E, W : Watcher < I, S, E >> { #[pin] state : State < I, N,
|
|
||||||
S, E, W >, }
|
pub struct NewSvcTask < I, N, S : HttpService < Body >, E, W : Watcher < I, S, E >> {
|
||||||
|
|
||||||
|
#[pin]
|
||||||
|
state : State <I, S, E, W >,
|
||||||
|
|
||||||
|
a: (N)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pin_project! {
|
pin_project! {
|
||||||
#[project = StateProj] pub (super) enum State < I, N, S : HttpService < Body >,
|
#[project = StateProj]
|
||||||
E, W : Watcher < I, S, E >> { Connecting { #[pin] connecting : Connecting < I, N,
|
|
||||||
E >, watcher : W, }, Connected { #[pin] future : W::Future, }, }
|
pub (super) enum State <I, S : HttpService < Body >, 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> {
|
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(connecting: Connecting<I, N, E>, watcher: W) -> Self {
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ where
|
||||||
UpgradeableConnection<I, S, E>,
|
UpgradeableConnection<I, S, E>,
|
||||||
fn(Pin<&mut UpgradeableConnection<I, S, E>>),
|
fn(Pin<&mut UpgradeableConnection<I, S, E>>),
|
||||||
>;
|
>;
|
||||||
fn watch(&self, conn: UpgradeableConnection<I, S, E>) -> Self::Future {
|
fn watch(&self) -> Self::Future {
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,5 @@ fn main() {
|
||||||
.with(warp::trace::request()),
|
.with(warp::trace::request()),
|
||||||
);
|
);
|
||||||
let make_svc = make_service_fn(move |_| future::ok::<_, Infallible>(svc.clone()));
|
let make_svc = make_service_fn(move |_| future::ok::<_, Infallible>(svc.clone()));
|
||||||
let addr = SocketAddr::from(([127, 0, 0, 1], 0));
|
tokio::spawn(hyper::Server::bind().serve(make_svc));
|
||||||
tokio::spawn(hyper::Server::bind(&addr).serve(make_svc));
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue