Skip to content

Commit 105d8b8

Browse files
author
Michael Eden
authored
Merge pull request #82 from Paul-Andre/master
Adding ability to accept connections and receive messages without blocking.
2 parents 7b40c07 + 3e738df commit 105d8b8

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

src/receiver.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ impl Receiver<WebSocketStream> {
5050
pub fn shutdown_all(&mut self) -> IoResult<()> {
5151
self.inner.get_mut().shutdown(Shutdown::Both)
5252
}
53+
54+
/// Changes whether the receiver is in nonblocking mode.
55+
///
56+
/// If it is in nonblocking mode and there is no incoming message, trying to receive a message
57+
/// will return an error instead of blocking.
58+
pub fn set_nonblocking(&self, nonblocking: bool) -> IoResult<()> {
59+
self.inner.get_ref().set_nonblocking(nonblocking)
60+
}
5361
}
5462

5563
impl<R: Read> ws::Receiver<DataFrame> for Receiver<R> {

src/sender.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ impl Sender<WebSocketStream> {
4545
pub fn shutdown_all(&mut self) -> IoResult<()> {
4646
self.inner.shutdown(Shutdown::Both)
4747
}
48+
49+
/// Changes whether the sender is in nonblocking mode.
50+
pub fn set_nonblocking(&self, nonblocking: bool) -> IoResult<()> {
51+
self.inner.set_nonblocking(nonblocking)
52+
}
4853
}
4954

5055
impl<W: Write> ws::Sender for Sender<W> {

src/server/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ impl<'a> Server<'a> {
126126
};
127127
Ok(Connection(try!(wsstream.try_clone()), try!(wsstream.try_clone())))
128128
}
129+
130+
/// Changes whether the Server is in nonblocking mode.
131+
///
132+
/// If it is in nonblocking mode, accept() will return an error instead of blocking when there
133+
/// are no incoming connections.
134+
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
135+
self.inner.set_nonblocking(nonblocking)
136+
}
129137
}
130138

131139
impl<'a> Iterator for Server<'a> {

src/stream.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,12 @@ impl WebSocketStream {
8383
WebSocketStream::Ssl(ref inner) => WebSocketStream::Ssl(try!(inner.try_clone())),
8484
})
8585
}
86+
87+
/// Changes whether the stream is in nonblocking mode.
88+
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
89+
match *self {
90+
WebSocketStream::Tcp(ref inner) => inner.set_nonblocking(nonblocking),
91+
WebSocketStream::Ssl(ref inner) => inner.get_ref().set_nonblocking(nonblocking),
92+
}
93+
}
8694
}

0 commit comments

Comments
 (0)