Udp socket readiness methods (#522)

This commit is contained in:
Andrew Cann 2018-08-08 10:41:27 +08:00 committed by Carl Lerche
parent e964c4136c
commit fdb2f61357
2 changed files with 38 additions and 4 deletions

View File

@ -159,10 +159,7 @@ impl TcpStream {
///
/// # Panics
///
/// This function panics if:
///
/// * `ready` contains bits besides `writable` and `hup`.
/// * called from outside of a task context.
/// 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()
}

View File

@ -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`].