mirror of https://github.com/fafhrd91/actix-net
add always_ready macro
This commit is contained in:
parent
e884eb4dcf
commit
55bbd27488
|
@ -75,9 +75,7 @@ impl<T: Address> Service<Connect<T>> for TcpConnector<T> {
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
type Future = Either<TcpConnectorResponse<T>, Ready<Result<Self::Response, Self::Error>>>;
|
type Future = Either<TcpConnectorResponse<T>, Ready<Result<Self::Response, Self::Error>>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
actix_service::always_ready!();
|
||||||
Poll::Ready(Ok(()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, req: Connect<T>) -> Self::Future {
|
fn call(&mut self, req: Connect<T>) -> Self::Future {
|
||||||
let port = req.port();
|
let port = req.port();
|
||||||
|
|
|
@ -110,9 +110,7 @@ impl<T: Address> Service<Connect<T>> for Resolver<T> {
|
||||||
Ready<Result<Connect<T>, Self::Error>>,
|
Ready<Result<Connect<T>, Self::Error>>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
actix_service::always_ready!();
|
||||||
Poll::Ready(Ok(()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, mut req: Connect<T>) -> Self::Future {
|
fn call(&mut self, mut req: Connect<T>) -> Self::Future {
|
||||||
if req.addr.is_some() {
|
if req.addr.is_some() {
|
||||||
|
|
|
@ -94,9 +94,7 @@ impl<T: Address> Service<Connect<T>> for ConnectService<T> {
|
||||||
type Error = ConnectError;
|
type Error = ConnectError;
|
||||||
type Future = ConnectServiceResponse<T>;
|
type Future = ConnectServiceResponse<T>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
actix_service::always_ready!();
|
||||||
Poll::Ready(Ok(()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, req: Connect<T>) -> Self::Future {
|
fn call(&mut self, req: Connect<T>) -> Self::Future {
|
||||||
ConnectServiceResponse {
|
ConnectServiceResponse {
|
||||||
|
@ -163,9 +161,7 @@ impl<T: Address + 'static> Service<Connect<T>> for TcpConnectService<T> {
|
||||||
type Error = ConnectError;
|
type Error = ConnectError;
|
||||||
type Future = TcpConnectServiceResponse<T>;
|
type Future = TcpConnectServiceResponse<T>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
actix_service::always_ready!();
|
||||||
Poll::Ready(Ok(()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, req: Connect<T>) -> Self::Future {
|
fn call(&mut self, req: Connect<T>) -> Self::Future {
|
||||||
TcpConnectServiceResponse {
|
TcpConnectServiceResponse {
|
||||||
|
|
|
@ -100,9 +100,7 @@ where
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
type Future = Either<ConnectAsyncExt<T, U>, Ready<Result<Self::Response, Self::Error>>>;
|
type Future = Either<ConnectAsyncExt<T, U>, Ready<Result<Self::Response, Self::Error>>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
actix_service::always_ready!();
|
||||||
Poll::Ready(Ok(()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, stream: Connection<T, U>) -> Self::Future {
|
fn call(&mut self, stream: Connection<T, U>) -> Self::Future {
|
||||||
trace!("SSL Handshake start for: {:?}", stream.host());
|
trace!("SSL Handshake start for: {:?}", stream.host());
|
||||||
|
@ -220,9 +218,7 @@ impl<T: Address + 'static> Service for OpensslConnectService<T> {
|
||||||
type Error = ConnectError;
|
type Error = ConnectError;
|
||||||
type Future = OpensslConnectServiceResponse<T>;
|
type Future = OpensslConnectServiceResponse<T>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
actix_service::always_ready!();
|
||||||
Poll::Ready(Ok(()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, req: Connect<T>) -> Self::Future {
|
fn call(&mut self, req: Connect<T>) -> Self::Future {
|
||||||
OpensslConnectServiceResponse {
|
OpensslConnectServiceResponse {
|
||||||
|
|
|
@ -96,9 +96,7 @@ where
|
||||||
type Error = std::io::Error;
|
type Error = std::io::Error;
|
||||||
type Future = ConnectAsyncExt<T, U>;
|
type Future = ConnectAsyncExt<T, U>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
actix_service::always_ready!();
|
||||||
Poll::Ready(Ok(()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, stream: Connection<T, U>) -> Self::Future {
|
fn call(&mut self, stream: Connection<T, U>) -> Self::Future {
|
||||||
trace!("SSL Handshake start for: {:?}", stream.host());
|
trace!("SSL Handshake start for: {:?}", stream.host());
|
||||||
|
|
|
@ -294,9 +294,7 @@ mod tests {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type Future = Ready<Result<Self::Response, Self::Error>>;
|
type Future = Ready<Result<Self::Response, Self::Error>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
crate::always_ready!();
|
||||||
Poll::Ready(Ok(()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, req: u8) -> Self::Future {
|
fn call(&mut self, req: u8) -> Self::Future {
|
||||||
let _ = req;
|
let _ = req;
|
||||||
|
|
|
@ -209,7 +209,7 @@ where
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::task::{Context, Poll};
|
use std::task::Poll;
|
||||||
|
|
||||||
use futures_util::future::{lazy, ok, Ready};
|
use futures_util::future::{lazy, ok, Ready};
|
||||||
|
|
||||||
|
@ -224,9 +224,7 @@ mod tests {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type Future = Ready<Result<(), ()>>;
|
type Future = Ready<Result<(), ()>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
crate::always_ready!();
|
||||||
Poll::Ready(Ok(()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, _: ()) -> Self::Future {
|
fn call(&mut self, _: ()) -> Self::Future {
|
||||||
ok(())
|
ok(())
|
||||||
|
|
|
@ -75,12 +75,9 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FactoryWrapper<SF, Req, C>
|
struct FactoryWrapper<SF, Req, Cfg> {
|
||||||
where
|
|
||||||
SF: ServiceFactory<Req>,
|
|
||||||
{
|
|
||||||
factory: SF,
|
factory: SF,
|
||||||
_t: PhantomData<(C, Req)>,
|
_t: PhantomData<(Req, Cfg)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<SF, Req, Cfg, Res, Err, InitErr> ServiceFactory<Req> for FactoryWrapper<SF, Req, Cfg>
|
impl<SF, Req, Cfg, Res, Err, InitErr> ServiceFactory<Req> for FactoryWrapper<SF, Req, Cfg>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::task::{Context, Poll};
|
use std::task::Poll;
|
||||||
|
|
||||||
use futures_util::future::{ok, Ready};
|
use futures_util::future::{ok, Ready};
|
||||||
|
|
||||||
|
@ -143,9 +143,7 @@ where
|
||||||
type Error = Err;
|
type Error = Err;
|
||||||
type Future = Fut;
|
type Future = Fut;
|
||||||
|
|
||||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
crate::always_ready!();
|
||||||
Poll::Ready(Ok(()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, req: Req) -> Self::Future {
|
fn call(&mut self, req: Req) -> Self::Future {
|
||||||
(self.f)(req)
|
(self.f)(req)
|
||||||
|
@ -200,9 +198,7 @@ where
|
||||||
type Error = Err;
|
type Error = Err;
|
||||||
type Future = Fut;
|
type Future = Fut;
|
||||||
|
|
||||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
crate::always_ready!();
|
||||||
Poll::Ready(Ok(()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, req: Req) -> Self::Future {
|
fn call(&mut self, req: Req) -> Self::Future {
|
||||||
(self.f)(req)
|
(self.f)(req)
|
||||||
|
|
|
@ -359,3 +359,15 @@ pub mod dev {
|
||||||
pub use crate::transform::ApplyTransform;
|
pub use crate::transform::ApplyTransform;
|
||||||
pub use crate::transform_err::TransformMapInitErr;
|
pub use crate::transform_err::TransformMapInitErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! always_ready {
|
||||||
|
() => {
|
||||||
|
fn poll_ready(
|
||||||
|
&mut self,
|
||||||
|
_: &mut ::std::task::Context<'_>,
|
||||||
|
) -> ::std::task::Poll<Result<(), Self::Error>> {
|
||||||
|
Poll::Ready(Ok(()))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -207,9 +207,7 @@ mod tests {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type Future = Ready<Result<(), ()>>;
|
type Future = Ready<Result<(), ()>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
crate::always_ready!();
|
||||||
Poll::Ready(Ok(()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, _: ()) -> Self::Future {
|
fn call(&mut self, _: ()) -> Self::Future {
|
||||||
ok(())
|
ok(())
|
||||||
|
|
|
@ -201,7 +201,7 @@ where
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::task::{Context, Poll};
|
use std::task::Poll;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -215,9 +215,7 @@ mod tests {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type Future = LocalBoxFuture<'static, Result<(), ()>>;
|
type Future = LocalBoxFuture<'static, Result<(), ()>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
actix_service::always_ready!();
|
||||||
Poll::Ready(Ok(()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, _: ()) -> Self::Future {
|
fn call(&mut self, _: ()) -> Self::Future {
|
||||||
actix_rt::time::delay_for(self.0)
|
actix_rt::time::delay_for(self.0)
|
||||||
|
|
Loading…
Reference in New Issue