protocol: less strict trait requirements

pull/7/head
Alexey Galakhov 8 years ago
parent ed276ba923
commit 334ceab2b0
  1. 31
      src/protocol/mod.rs

@ -40,10 +40,7 @@ pub struct WebSocket<Stream> {
pong: Option<Frame>,
}
impl<Stream> WebSocket<Stream>
where Stream: Read + Write
{
impl<Stream> WebSocket<Stream> {
/// Convert a raw socket into a WebSocket without performing a handshake.
pub fn from_raw_socket(stream: Stream, role: Role) -> Self {
WebSocket::from_frame_socket(FrameSocket::new(stream), role)
@ -54,6 +51,20 @@ impl<Stream> WebSocket<Stream>
WebSocket::from_frame_socket(FrameSocket::from_partially_read(stream, part), role)
}
/// Convert a frame socket into a WebSocket.
fn from_frame_socket(socket: FrameSocket<Stream>, role: Role) -> Self {
WebSocket {
role: role,
socket: socket,
state: WebSocketState::Active,
incomplete: None,
send_queue: VecDeque::new(),
pong: None,
}
}
}
impl<Stream: Read + Write> WebSocket<Stream> {
/// Read a message from stream, if possible.
///
/// This function sends pong and close responses automatically.
@ -141,18 +152,6 @@ impl<Stream> WebSocket<Stream>
}
}
/// Convert a frame socket into a WebSocket.
fn from_frame_socket(socket: FrameSocket<Stream>, role: Role) -> Self {
WebSocket {
role: role,
socket: socket,
state: WebSocketState::Active,
incomplete: None,
send_queue: VecDeque::new(),
pong: None,
}
}
/// Try to decode one message frame. May return None.
fn read_message_frame(&mut self) -> Result<Option<Message>> {
if let Some(mut frame) = self.socket.read_frame()? {

Loading…
Cancel
Save