mirror of
https://github.com/actix/actix-extras.git
synced 2025-07-01 12:15:08 +02:00
add websocket transport and test
This commit is contained in:
@ -15,10 +15,12 @@ mod codec;
|
||||
mod frame;
|
||||
mod mask;
|
||||
mod proto;
|
||||
mod transport;
|
||||
|
||||
pub use self::codec::Message;
|
||||
pub use self::codec::{Codec, Message};
|
||||
pub use self::frame::Frame;
|
||||
pub use self::proto::{CloseCode, CloseReason, OpCode};
|
||||
pub use self::transport::Transport;
|
||||
|
||||
/// Websocket protocol errors
|
||||
#[derive(Fail, Debug)]
|
||||
|
50
src/ws/transport.rs
Normal file
50
src/ws/transport.rs
Normal file
@ -0,0 +1,50 @@
|
||||
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};
|
||||
|
||||
use super::{Codec, Message};
|
||||
|
||||
pub struct Transport<S, T>
|
||||
where
|
||||
S: Service,
|
||||
T: AsyncRead + AsyncWrite,
|
||||
{
|
||||
inner: FramedTransport<S, T, Codec>,
|
||||
}
|
||||
|
||||
impl<S, T> Transport<S, T>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request = Message, Response = Message>,
|
||||
S::Future: 'static,
|
||||
S::Error: 'static,
|
||||
{
|
||||
pub fn new<F: IntoService<S>>(io: T, service: F) -> Self {
|
||||
Transport {
|
||||
inner: FramedTransport::new(Framed::new(io, Codec::new()), service),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with<F: IntoService<S>>(framed: Framed<T, Codec>, service: F) -> Self {
|
||||
Transport {
|
||||
inner: FramedTransport::new(framed, service),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, T> Future for Transport<S, T>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request = Message, Response = Message>,
|
||||
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()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user