diff options
Diffstat (limited to 'tokio/src/io/util/async_read_ext.rs')
-rw-r--r-- | tokio/src/io/util/async_read_ext.rs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/tokio/src/io/util/async_read_ext.rs b/tokio/src/io/util/async_read_ext.rs index 0ab66c28..96a5f70d 100644 --- a/tokio/src/io/util/async_read_ext.rs +++ b/tokio/src/io/util/async_read_ext.rs @@ -1,6 +1,6 @@ use crate::io::util::chain::{chain, Chain}; use crate::io::util::read::{read, Read}; -use crate::io::util::read_buf::{read_buf, ReadBuf}; +use crate::io::util::read_buf::{poll_read_buf, read_buf, ReadBuf}; use crate::io::util::read_exact::{read_exact, ReadExact}; use crate::io::util::read_int::{ ReadI128, ReadI128Le, ReadI16, ReadI16Le, ReadI32, ReadI32Le, ReadI64, ReadI64Le, ReadI8, @@ -14,6 +14,8 @@ use crate::io::util::take::{take, Take}; use crate::io::AsyncRead; use bytes::BufMut; +use std::io; +use std::task::{Context, Poll}; cfg_io_util! { /// Defines numeric reader @@ -185,7 +187,7 @@ cfg_io_util! { /// /// On a successful read, the number of read bytes is returned. If the /// supplied buffer is not empty and the function returns `Ok(0)` then - /// the source as reached an "end-of-file" event. + /// the source has reached an "end-of-file" event. /// /// # Errors /// @@ -231,6 +233,28 @@ cfg_io_util! { read_buf(self, buf) } + /// Attempts to pull some bytes from this source into the specified buffer, + /// advancing the buffer's internal cursor if the underlying reader is ready. + /// + /// Usually, only a single `read` syscall is issued, even if there is + /// more space in the supplied buffer. + /// + /// # Return + /// + /// On a successful read, the number of read bytes is returned. If the + /// supplied buffer is not empty and the function returns `Ok(0)` then + /// the source has reached an "end-of-file" event. + /// + /// # Errors + /// + /// If this function encounters any form of I/O or other error, an error + /// variant will be returned. If an error is returned then it must be + /// guaranteed that no bytes were read. + /// ``` + fn poll_read_buf<'a, B>(&'a mut self, buf: &'a mut B, cx: &mut Context<'_>) -> Poll<io::Result<usize>> where Self: Unpin + Sized, B: BufMut { + poll_read_buf(self, buf, cx) + } + /// Reads the exact number of bytes required to fill `buf`. /// /// Equivalent to: |