diff options
author | Andrew Cann <shum@canndrew.org> | 2018-08-08 10:41:27 +0800 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2018-08-07 19:41:27 -0700 |
commit | fdb2f613577b0777975950b0181700a889c88807 (patch) | |
tree | efb693de5c234d0da75623af0a912f7197f2a369 /tokio-udp | |
parent | e964c4136c91c535fb2dfee0a3327dc5a6599903 (diff) |
Udp socket readiness methods (#522)
Diffstat (limited to 'tokio-udp')
-rw-r--r-- | tokio-udp/src/socket.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tokio-udp/src/socket.rs b/tokio-udp/src/socket.rs index aaf6b8f7..731af300 100644 --- a/tokio-udp/src/socket.rs +++ b/tokio-udp/src/socket.rs @@ -249,6 +249,43 @@ impl UdpSocket { RecvDgram::new(self, buf) } + /// Check the UDP socket's read readiness state. + /// + /// The mask argument allows specifying what readiness to notify on. This + /// can be any value, including platform specific readiness, **except** + /// `writable`. + /// + /// If the socket is not ready for receiving then `Async::NotReady` is + /// returned and the current task is notified once a new event is received. + /// + /// The socket will remain in a read-ready state until calls to `poll_recv` + /// return `NotReady`. + /// + /// # Panics + /// + /// This function panics if: + /// + /// * `ready` includes writable. + /// * called from outside of a task context. + pub fn poll_read_ready(&self, mask: mio::Ready) -> Poll<mio::Ready, io::Error> { + self.io.poll_read_ready(mask) + } + + /// Check the UDP socket's write readiness state. + /// + /// If the socket is not ready for sending then `Async::NotReady` is + /// returned and the current task is notified once a new event is received. + /// + /// The I/O resource will remain in a write-ready state until calls to + /// `poll_send` return `NotReady`. + /// + /// # Panics + /// + /// This function panics if called from outside of a task context. + pub fn poll_write_ready(&self) -> Poll<mio::Ready, io::Error> { + self.io.poll_write_ready() + } + /// Gets the value of the `SO_BROADCAST` option for this socket. /// /// For more information about this option, see [`set_broadcast`]. |