Update to the latest `tungstenite-rs` version

pull/1/head
Daniel Abramov 6 years ago
parent 4c60589773
commit e2cdf11bc8
  1. 4
      Cargo.toml
  2. 21
      src/lib.rs

@ -21,9 +21,7 @@ futures = "0.1.23"
tokio-io = "0.1.7" tokio-io = "0.1.7"
[dependencies.tungstenite] [dependencies.tungstenite]
# Uncomment when `tungstenite-rs` is released. version = "0.8.0"
# version = "0.7.0"
git = "https://github.com/snapview/tungstenite-rs"
default-features = false default-features = false
[dependencies.bytes] [dependencies.bytes]

@ -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()
} }
} }

Loading…
Cancel
Save