mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-19 00:00:09 +02:00
net: clarify when wakeups are sent (#3310)
This commit is contained in:
@@ -53,6 +53,10 @@ impl ReadHalf<'_> {
|
||||
/// the queue, registering the current task for wakeup if data is not yet
|
||||
/// available.
|
||||
///
|
||||
/// Note that on multiple calls to `poll_peek` or `poll_read`, only the
|
||||
/// `Waker` from the `Context` passed to the most recent call is scheduled
|
||||
/// to receive a wakeup.
|
||||
///
|
||||
/// See the [`TcpStream::poll_peek`] level documenation for more details.
|
||||
///
|
||||
/// # Examples
|
||||
|
||||
@@ -108,6 +108,10 @@ impl OwnedReadHalf {
|
||||
/// the queue, registering the current task for wakeup if data is not yet
|
||||
/// available.
|
||||
///
|
||||
/// Note that on multiple calls to `poll_peek` or `poll_read`, only the
|
||||
/// `Waker` from the `Context` passed to the most recent call is scheduled
|
||||
/// to receive a wakeup.
|
||||
///
|
||||
/// See the [`TcpStream::poll_peek`] level documenation for more details.
|
||||
///
|
||||
/// # Examples
|
||||
|
||||
+49
-11
@@ -282,6 +282,11 @@ impl TcpStream {
|
||||
/// the queue, registering the current task for wakeup if data is not yet
|
||||
/// available.
|
||||
///
|
||||
/// Note that on multiple calls to `poll_peek`, `poll_read` or
|
||||
/// `poll_read_ready`, only the `Waker` from the `Context` passed to the
|
||||
/// most recent call is scheduled to receive a wakeup. (However,
|
||||
/// `poll_write` retains a second, independent waker.)
|
||||
///
|
||||
/// # Return value
|
||||
///
|
||||
/// The function returns:
|
||||
@@ -456,10 +461,32 @@ impl TcpStream {
|
||||
|
||||
/// Polls for read readiness.
|
||||
///
|
||||
/// If the tcp stream is not currently ready for reading, this method will
|
||||
/// store a clone of the `Waker` from the provided `Context`. When the tcp
|
||||
/// stream becomes ready for reading, `Waker::wake` will be called on the
|
||||
/// waker.
|
||||
///
|
||||
/// Note that on multiple calls to `poll_read_ready`, `poll_read` or
|
||||
/// `poll_peek`, only the `Waker` from the `Context` passed to the most
|
||||
/// recent call is scheduled to receive a wakeup. (However,
|
||||
/// `poll_write_ready` retains a second, independent waker.)
|
||||
///
|
||||
/// This function is intended for cases where creating and pinning a future
|
||||
/// via [`readable`] is not feasible. Where possible, using [`readable`] is
|
||||
/// preferred, as this supports polling from multiple tasks at once.
|
||||
///
|
||||
/// # Return value
|
||||
///
|
||||
/// The function returns:
|
||||
///
|
||||
/// * `Poll::Pending` if the tcp stream is not ready for reading.
|
||||
/// * `Poll::Ready(Ok(()))` if the tcp stream is ready for reading.
|
||||
/// * `Poll::Ready(Err(e))` if an error is encountered.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may encounter any standard I/O error except `WouldBlock`.
|
||||
///
|
||||
/// [`readable`]: method@Self::readable
|
||||
pub fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
self.io.registration().poll_read_ready(cx).map_ok(|_| ())
|
||||
@@ -578,10 +605,32 @@ impl TcpStream {
|
||||
|
||||
/// Polls for write readiness.
|
||||
///
|
||||
/// If the tcp stream is not currently ready for writing, this method will
|
||||
/// store a clone of the `Waker` from the provided `Context`. When the tcp
|
||||
/// stream becomes ready for writing, `Waker::wake` will be called on the
|
||||
/// waker.
|
||||
///
|
||||
/// Note that on multiple calls to `poll_write_ready` or `poll_write`, only
|
||||
/// the `Waker` from the `Context` passed to the most recent call is
|
||||
/// scheduled to receive a wakeup. (However, `poll_read_ready` retains a
|
||||
/// second, independent waker.)
|
||||
///
|
||||
/// This function is intended for cases where creating and pinning a future
|
||||
/// via [`writable`] is not feasible. Where possible, using [`writable`] is
|
||||
/// preferred, as this supports polling from multiple tasks at once.
|
||||
///
|
||||
/// # Return value
|
||||
///
|
||||
/// The function returns:
|
||||
///
|
||||
/// * `Poll::Pending` if the tcp stream is not ready for writing.
|
||||
/// * `Poll::Ready(Ok(()))` if the tcp stream is ready for writing.
|
||||
/// * `Poll::Ready(Err(e))` if an error is encountered.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may encounter any standard I/O error except `WouldBlock`.
|
||||
///
|
||||
/// [`writable`]: method@Self::writable
|
||||
pub fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
self.io.registration().poll_write_ready(cx).map_ok(|_| ())
|
||||
@@ -878,17 +927,6 @@ impl TcpStream {
|
||||
split_owned(self)
|
||||
}
|
||||
|
||||
// == Poll IO functions that takes `&self` ==
|
||||
//
|
||||
// They are not public because (taken from the doc of `PollEvented`):
|
||||
//
|
||||
// While `PollEvented` is `Sync` (if the underlying I/O type is `Sync`), the
|
||||
// caller must ensure that there are at most two tasks that use a
|
||||
// `PollEvented` instance concurrently. One for reading and one for writing.
|
||||
// While violating this requirement is "safe" from a Rust memory model point
|
||||
// of view, it will result in unexpected behavior in the form of lost
|
||||
// notifications and tasks hanging.
|
||||
|
||||
pub(crate) fn poll_read_priv(
|
||||
&self,
|
||||
cx: &mut Context<'_>,
|
||||
|
||||
@@ -169,10 +169,32 @@ impl UnixStream {
|
||||
|
||||
/// Polls for read readiness.
|
||||
///
|
||||
/// If the unix stream is not currently ready for reading, this method will
|
||||
/// store a clone of the `Waker` from the provided `Context`. When the unix
|
||||
/// stream becomes ready for reading, `Waker::wake` will be called on the
|
||||
/// waker.
|
||||
///
|
||||
/// Note that on multiple calls to `poll_read_ready` or `poll_read`, only
|
||||
/// the `Waker` from the `Context` passed to the most recent call is
|
||||
/// scheduled to receive a wakeup. (However, `poll_write_ready` retains a
|
||||
/// second, independent waker.)
|
||||
///
|
||||
/// This function is intended for cases where creating and pinning a future
|
||||
/// via [`readable`] is not feasible. Where possible, using [`readable`] is
|
||||
/// preferred, as this supports polling from multiple tasks at once.
|
||||
///
|
||||
/// # Return value
|
||||
///
|
||||
/// The function returns:
|
||||
///
|
||||
/// * `Poll::Pending` if the unix stream is not ready for reading.
|
||||
/// * `Poll::Ready(Ok(()))` if the unix stream is ready for reading.
|
||||
/// * `Poll::Ready(Err(e))` if an error is encountered.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may encounter any standard I/O error except `WouldBlock`.
|
||||
///
|
||||
/// [`readable`]: method@Self::readable
|
||||
pub fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
self.io.registration().poll_read_ready(cx).map_ok(|_| ())
|
||||
@@ -293,10 +315,32 @@ impl UnixStream {
|
||||
|
||||
/// Polls for write readiness.
|
||||
///
|
||||
/// If the unix stream is not currently ready for writing, this method will
|
||||
/// store a clone of the `Waker` from the provided `Context`. When the unix
|
||||
/// stream becomes ready for writing, `Waker::wake` will be called on the
|
||||
/// waker.
|
||||
///
|
||||
/// Note that on multiple calls to `poll_write_ready` or `poll_write`, only
|
||||
/// the `Waker` from the `Context` passed to the most recent call is
|
||||
/// scheduled to receive a wakeup. (However, `poll_read_ready` retains a
|
||||
/// second, independent waker.)
|
||||
///
|
||||
/// This function is intended for cases where creating and pinning a future
|
||||
/// via [`writable`] is not feasible. Where possible, using [`writable`] is
|
||||
/// preferred, as this supports polling from multiple tasks at once.
|
||||
///
|
||||
/// # Return value
|
||||
///
|
||||
/// The function returns:
|
||||
///
|
||||
/// * `Poll::Pending` if the unix stream is not ready for writing.
|
||||
/// * `Poll::Ready(Ok(()))` if the unix stream is ready for writing.
|
||||
/// * `Poll::Ready(Err(e))` if an error is encountered.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may encounter any standard I/O error except `WouldBlock`.
|
||||
///
|
||||
/// [`writable`]: method@Self::writable
|
||||
pub fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
self.io.registration().poll_write_ready(cx).map_ok(|_| ())
|
||||
|
||||
Reference in New Issue
Block a user