1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-06-02 21:39:26 +00:00
actix-web/actix-http/src/ws/transport.rs

52 lines
1.3 KiB
Rust
Raw Normal View History

2019-11-18 12:42:27 +00:00
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
2018-12-11 02:08:33 +00:00
use actix_codec::{AsyncRead, AsyncWrite, Framed};
use actix_service::{IntoService, Service};
use actix_utils::framed::{FramedTransport, FramedTransportError};
2018-10-05 21:30:40 +00:00
2018-10-10 20:20:00 +00:00
use super::{Codec, Frame, Message};
2018-10-05 21:30:40 +00:00
pub struct Transport<S, T>
where
S: Service<Request = Frame, Response = Message> + 'static,
2019-11-19 12:54:19 +00:00
T: AsyncRead + AsyncWrite,
2018-10-05 21:30:40 +00:00
{
inner: FramedTransport<S, T, Codec>,
}
impl<S, T> Transport<S, T>
where
2019-11-19 12:54:19 +00:00
T: AsyncRead + AsyncWrite,
S: Service<Request = Frame, Response = Message>,
2018-10-05 21:30:40 +00:00
S::Future: 'static,
2019-11-19 12:54:19 +00:00
S::Error: 'static,
2018-10-05 21:30:40 +00:00
{
pub fn new<F: IntoService<S>>(io: T, service: F) -> Self {
2018-10-05 21:30:40 +00:00
Transport {
inner: FramedTransport::new(Framed::new(io, Codec::new()), service),
}
}
pub fn with<F: IntoService<S>>(framed: Framed<T, Codec>, service: F) -> Self {
2018-10-05 21:30:40 +00:00
Transport {
inner: FramedTransport::new(framed, service),
}
}
}
impl<S, T> Future for Transport<S, T>
where
2019-11-19 12:54:19 +00:00
T: AsyncRead + AsyncWrite,
S: Service<Request = Frame, Response = Message>,
2018-10-05 21:30:40 +00:00
S::Future: 'static,
2019-11-19 12:54:19 +00:00
S::Error: 'static,
2018-10-05 21:30:40 +00:00
{
2019-11-18 12:42:27 +00:00
type Output = Result<(), FramedTransportError<S::Error, Codec>>;
2018-10-05 21:30:40 +00:00
2019-12-07 18:46:51 +00:00
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
2019-11-18 12:42:27 +00:00
Pin::new(&mut self.inner).poll(cx)
2018-10-05 21:30:40 +00:00
}
}