diff --git a/src/receiver.rs b/src/receiver.rs index 3dfbc48f14..03cfab6197 100644 --- a/src/receiver.rs +++ b/src/receiver.rs @@ -50,6 +50,14 @@ impl Receiver { 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 ws::Receiver for Receiver { diff --git a/src/sender.rs b/src/sender.rs index 62e41ad599..a4390f4741 100644 --- a/src/sender.rs +++ b/src/sender.rs @@ -45,6 +45,11 @@ impl Sender { 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 ws::Sender for Sender { diff --git a/src/server/mod.rs b/src/server/mod.rs index d59fa9d43a..8236b1c089 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -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> { diff --git a/src/stream.rs b/src/stream.rs index 8f5480a62a..623b280bbd 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -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), + } + } }