2018-10-05 23:30:40 +02:00
|
|
|
use actix_net::codec::Framed;
|
|
|
|
use actix_net::framed::{FramedTransport, FramedTransportError};
|
|
|
|
use actix_net::service::{IntoService, Service};
|
|
|
|
use futures::{Future, Poll};
|
|
|
|
use tokio_io::{AsyncRead, AsyncWrite};
|
|
|
|
|
2018-10-10 22:20:00 +02:00
|
|
|
use super::{Codec, Frame, Message};
|
2018-10-05 23:30:40 +02:00
|
|
|
|
|
|
|
pub struct Transport<S, T>
|
|
|
|
where
|
2018-11-30 20:57:57 +01:00
|
|
|
S: Service<Frame, Response = Message>,
|
2018-10-05 23:30:40 +02:00
|
|
|
T: AsyncRead + AsyncWrite,
|
|
|
|
{
|
|
|
|
inner: FramedTransport<S, T, Codec>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<S, T> Transport<S, T>
|
|
|
|
where
|
|
|
|
T: AsyncRead + AsyncWrite,
|
2018-11-30 20:57:57 +01:00
|
|
|
S: Service<Frame, Response = Message>,
|
2018-10-05 23:30:40 +02:00
|
|
|
S::Future: 'static,
|
|
|
|
S::Error: 'static,
|
|
|
|
{
|
2018-11-30 20:57:57 +01:00
|
|
|
pub fn new<F: IntoService<S, Frame>>(io: T, service: F) -> Self {
|
2018-10-05 23:30:40 +02:00
|
|
|
Transport {
|
|
|
|
inner: FramedTransport::new(Framed::new(io, Codec::new()), service),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-30 20:57:57 +01:00
|
|
|
pub fn with<F: IntoService<S, Frame>>(framed: Framed<T, Codec>, service: F) -> Self {
|
2018-10-05 23:30:40 +02:00
|
|
|
Transport {
|
|
|
|
inner: FramedTransport::new(framed, service),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<S, T> Future for Transport<S, T>
|
|
|
|
where
|
|
|
|
T: AsyncRead + AsyncWrite,
|
2018-11-30 20:57:57 +01:00
|
|
|
S: Service<Frame, Response = Message>,
|
2018-10-05 23:30:40 +02:00
|
|
|
S::Future: 'static,
|
|
|
|
S::Error: 'static,
|
|
|
|
{
|
|
|
|
type Item = ();
|
|
|
|
type Error = FramedTransportError<S::Error, Codec>;
|
|
|
|
|
|
|
|
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
|
|
|
self.inner.poll()
|
|
|
|
}
|
|
|
|
}
|