Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ impl Receiver<WebSocketStream> {
pub fn shutdown_all(&mut self) -> IoResult<()> {
self.inner.get_mut().shutdown(Shutdown::Both)
}

/// Changes whether the receiver is in nonblocking mode.
///
/// If it is in nonblocking mode and there is no incoming message, trying to receive a message
/// will return an error instead of blocking.
pub fn set_nonblocking(&self, nonblocking: bool) -> IoResult<()> {
self.inner.get_ref().set_nonblocking(nonblocking)
}
}

impl<R: Read> ws::Receiver<DataFrame> for Receiver<R> {
Expand Down
5 changes: 5 additions & 0 deletions src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ impl Sender<WebSocketStream> {
pub fn shutdown_all(&mut self) -> IoResult<()> {
self.inner.shutdown(Shutdown::Both)
}

/// Changes whether the sender is in nonblocking mode.
pub fn set_nonblocking(&self, nonblocking: bool) -> IoResult<()> {
self.inner.set_nonblocking(nonblocking)
}
}

impl<W: Write> ws::Sender for Sender<W> {
Expand Down
8 changes: 8 additions & 0 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ impl<'a> Server<'a> {
};
Ok(Connection(try!(wsstream.try_clone()), try!(wsstream.try_clone())))
}

/// Changes whether the Server is in nonblocking mode.
///
/// If it is in nonblocking mode, accept() will return an error instead of blocking when there
/// are no incoming connections.
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
self.inner.set_nonblocking(nonblocking)
}
}

impl<'a> Iterator for Server<'a> {
Expand Down
8 changes: 8 additions & 0 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,12 @@ impl WebSocketStream {
WebSocketStream::Ssl(ref inner) => WebSocketStream::Ssl(try!(inner.try_clone())),
})
}

/// Changes whether the stream is in nonblocking mode.
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
match *self {
WebSocketStream::Tcp(ref inner) => inner.set_nonblocking(nonblocking),
WebSocketStream::Ssl(ref inner) => inner.get_ref().set_nonblocking(nonblocking),
}
}
}