diff --git a/src/lib.rs b/src/lib.rs index 36d7d0e0f..cd74f6f0d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -107,9 +107,6 @@ mod pipeline; mod server; mod worker; mod channel; -mod wsframe; -mod wsproto; -mod wscontext; mod h1; mod h2; mod h1writer; diff --git a/src/wscontext.rs b/src/ws/context.rs similarity index 89% rename from src/wscontext.rs rename to src/ws/context.rs index 41206e457..13cb01c03 100644 --- a/src/wscontext.rs +++ b/src/ws/context.rs @@ -13,18 +13,17 @@ use actix::dev::{queue, AsyncContextApi, use body::{Body, Binary}; use error::{Error, Result, ErrorInternalServerError}; use httprequest::HttpRequest; -use context::{Frame, ActorHttpContext, Drain}; +use context::{Frame as ContextFrame, ActorHttpContext, Drain}; -use wsframe; -use wsproto::*; -pub use wsproto::CloseCode; +use ws::frame::Frame; +use ws::proto::{OpCode, CloseCode}; /// Http actor execution context pub struct WebsocketContext where A: Actor>, { inner: ContextImpl, - stream: VecDeque, + stream: VecDeque, request: HttpRequest, disconnected: bool, } @@ -108,7 +107,7 @@ impl WebsocketContext where A: Actor { #[inline] fn write>(&mut self, data: B) { if !self.disconnected { - self.stream.push_back(Frame::Payload(Some(data.into()))); + self.stream.push_back(ContextFrame::Payload(Some(data.into()))); } else { warn!("Trying to write to disconnected response"); } @@ -128,7 +127,7 @@ impl WebsocketContext where A: Actor { /// Send text frame pub fn text(&mut self, text: &str) { - let mut frame = wsframe::Frame::message(Vec::from(text), OpCode::Text, true); + let mut frame = Frame::message(Vec::from(text), OpCode::Text, true); let mut buf = Vec::new(); frame.format(&mut buf).unwrap(); @@ -137,7 +136,7 @@ impl WebsocketContext where A: Actor { /// Send binary frame pub fn binary>(&mut self, data: B) { - let mut frame = wsframe::Frame::message(data, OpCode::Binary, true); + let mut frame = Frame::message(data, OpCode::Binary, true); let mut buf = Vec::new(); frame.format(&mut buf).unwrap(); @@ -146,7 +145,7 @@ impl WebsocketContext where A: Actor { /// Send ping frame pub fn ping(&mut self, message: &str) { - let mut frame = wsframe::Frame::message(Vec::from(message), OpCode::Ping, true); + let mut frame = Frame::message(Vec::from(message), OpCode::Ping, true); let mut buf = Vec::new(); frame.format(&mut buf).unwrap(); @@ -155,7 +154,7 @@ impl WebsocketContext where A: Actor { /// Send pong frame pub fn pong(&mut self, message: &str) { - let mut frame = wsframe::Frame::message(Vec::from(message), OpCode::Pong, true); + let mut frame = Frame::message(Vec::from(message), OpCode::Pong, true); let mut buf = Vec::new(); frame.format(&mut buf).unwrap(); @@ -164,7 +163,7 @@ impl WebsocketContext where A: Actor { /// Send close frame pub fn close(&mut self, code: CloseCode, reason: &str) { - let mut frame = wsframe::Frame::close(code, reason); + let mut frame = Frame::close(code, reason); let mut buf = Vec::new(); frame.format(&mut buf).unwrap(); self.write(buf); @@ -174,7 +173,7 @@ impl WebsocketContext where A: Actor { pub fn drain(&mut self) -> Drain { let (tx, rx) = oneshot::channel(); self.inner.modify(); - self.stream.push_back(Frame::Drain(tx)); + self.stream.push_back(ContextFrame::Drain(tx)); Drain::new(rx) } @@ -213,7 +212,7 @@ impl ActorHttpContext for WebsocketContext where A: Actor Poll, Error> { + fn poll(&mut self) -> Poll, Error> { let ctx: &mut WebsocketContext = unsafe { mem::transmute(self as &mut WebsocketContext) }; diff --git a/src/wsframe.rs b/src/ws/frame.rs similarity index 99% rename from src/wsframe.rs rename to src/ws/frame.rs index be036a4e8..ff2fd188b 100644 --- a/src/wsframe.rs +++ b/src/ws/frame.rs @@ -4,7 +4,7 @@ use std::iter::FromIterator; use bytes::BytesMut; use body::Binary; -use wsproto::{OpCode, CloseCode}; +use ws::proto::{OpCode, CloseCode}; fn apply_mask(buf: &mut [u8], mask: &[u8; 4]) { diff --git a/src/ws.rs b/src/ws/mod.rs similarity index 98% rename from src/ws.rs rename to src/ws/mod.rs index 8b762798b..91c43c999 100644 --- a/src/ws.rs +++ b/src/ws/mod.rs @@ -55,10 +55,14 @@ use error::{Error, WsHandshakeError}; use httprequest::HttpRequest; use httpresponse::{ConnectionType, HttpResponse, HttpResponseBuilder}; -use wsframe; -use wsproto::*; -pub use wsproto::CloseCode; -pub use wscontext::WebsocketContext; +mod frame; +mod proto; +mod context; + +use ws::frame::Frame; +use ws::proto::{hash_key, OpCode}; +pub use ws::proto::CloseCode; +pub use ws::context::WebsocketContext; const SEC_WEBSOCKET_ACCEPT: &str = "SEC-WEBSOCKET-ACCEPT"; const SEC_WEBSOCKET_KEY: &str = "SEC-WEBSOCKET-KEY"; @@ -207,7 +211,7 @@ impl Stream for WsStream { } loop { - match wsframe::Frame::parse(&mut self.buf) { + match Frame::parse(&mut self.buf) { Ok(Some(frame)) => { // trace!("WsFrame {}", frame); let (_finished, opcode, payload) = frame.unpack(); diff --git a/src/wsproto.rs b/src/ws/proto.rs similarity index 100% rename from src/wsproto.rs rename to src/ws/proto.rs