|
|
@ -170,7 +170,6 @@ where |
|
|
|
/// and unit tests for this crate.
|
|
|
|
/// and unit tests for this crate.
|
|
|
|
pub struct WebSocketStream<S> { |
|
|
|
pub struct WebSocketStream<S> { |
|
|
|
inner: WebSocket<S>, |
|
|
|
inner: WebSocket<S>, |
|
|
|
stream_ended: bool, |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<S> WebSocketStream<S> { |
|
|
|
impl<S> WebSocketStream<S> { |
|
|
@ -198,7 +197,6 @@ impl<S> WebSocketStream<S> { |
|
|
|
fn new(ws: WebSocket<S>) -> Self { |
|
|
|
fn new(ws: WebSocket<S>) -> Self { |
|
|
|
WebSocketStream { |
|
|
|
WebSocketStream { |
|
|
|
inner: ws, |
|
|
|
inner: ws, |
|
|
|
stream_ended: false, |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -215,17 +213,14 @@ impl<T> Stream for WebSocketStream<T> where T: AsyncRead + AsyncWrite { |
|
|
|
type Error = WsError; |
|
|
|
type Error = WsError; |
|
|
|
|
|
|
|
|
|
|
|
fn poll(&mut self) -> Poll<Option<Message>, WsError> { |
|
|
|
fn poll(&mut self) -> Poll<Option<Message>, WsError> { |
|
|
|
if self.stream_ended { |
|
|
|
self.inner |
|
|
|
self.stream_ended = false; |
|
|
|
.read_message() |
|
|
|
return Ok(Async::Ready(None)) |
|
|
|
.map(|msg| Some(msg)) |
|
|
|
} |
|
|
|
.to_async() |
|
|
|
|
|
|
|
.or_else(|err| match err { |
|
|
|
self.inner.read_message().map(|m| { |
|
|
|
WsError::ConnectionClosed => Ok(Async::Ready(None)), |
|
|
|
if m.is_close() { |
|
|
|
err => Err(err) |
|
|
|
self.stream_ended = true; |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
Some(m) |
|
|
|
|
|
|
|
}).to_async() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|