summaryrefslogtreecommitdiffstats
path: root/tokio/src/net/tcp
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2020-10-09 09:16:42 -0700
committerGitHub <noreply@github.com>2020-10-09 09:16:42 -0700
commitee597347c5e612611142ece09c79e55f2d243590 (patch)
tree5ef874817b2a75a9eea7a807cac48ec6ae776733 /tokio/src/net/tcp
parent41ac1ae2bc9b2e4b6d03205bde19a4bbc20b368d (diff)
net: switch socket methods to &self (#2934)
Switches various socket methods from &mut self to &self. This uses the intrusive waker infrastructure to handle multiple waiters. Refs: #2928
Diffstat (limited to 'tokio/src/net/tcp')
-rw-r--r--tokio/src/net/tcp/split.rs2
-rw-r--r--tokio/src/net/tcp/split_owned.rs2
-rw-r--r--tokio/src/net/tcp/stream.rs18
3 files changed, 8 insertions, 14 deletions
diff --git a/tokio/src/net/tcp/split.rs b/tokio/src/net/tcp/split.rs
index 6e927f05..9a257f8b 100644
--- a/tokio/src/net/tcp/split.rs
+++ b/tokio/src/net/tcp/split.rs
@@ -81,7 +81,7 @@ impl ReadHalf<'_> {
///
/// [`TcpStream::poll_peek`]: TcpStream::poll_peek
pub fn poll_peek(&mut self, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<io::Result<usize>> {
- self.0.poll_peek2(cx, buf)
+ self.0.poll_peek(cx, buf)
}
/// Receives data on the socket from the remote address to which it is
diff --git a/tokio/src/net/tcp/split_owned.rs b/tokio/src/net/tcp/split_owned.rs
index 2f35f495..4b4e2636 100644
--- a/tokio/src/net/tcp/split_owned.rs
+++ b/tokio/src/net/tcp/split_owned.rs
@@ -136,7 +136,7 @@ impl OwnedReadHalf {
///
/// [`TcpStream::poll_peek`]: TcpStream::poll_peek
pub fn poll_peek(&mut self, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<io::Result<usize>> {
- self.inner.poll_peek2(cx, buf)
+ self.inner.poll_peek(cx, buf)
}
/// Receives data on the socket from the remote address to which it is
diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs
index 3f9d6670..ee24ee32 100644
--- a/tokio/src/net/tcp/stream.rs
+++ b/tokio/src/net/tcp/stream.rs
@@ -257,7 +257,7 @@ impl TcpStream {
///
/// #[tokio::main]
/// async fn main() -> io::Result<()> {
- /// let mut stream = TcpStream::connect("127.0.0.1:8000").await?;
+ /// let stream = TcpStream::connect("127.0.0.1:8000").await?;
/// let mut buf = [0; 10];
///
/// poll_fn(|cx| {
@@ -267,15 +267,7 @@ impl TcpStream {
/// Ok(())
/// }
/// ```
- pub fn poll_peek(&mut self, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<io::Result<usize>> {
- self.poll_peek2(cx, buf)
- }
-
- pub(super) fn poll_peek2(
- &self,
- cx: &mut Context<'_>,
- buf: &mut [u8],
- ) -> Poll<io::Result<usize>> {
+ pub fn poll_peek(&self, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<io::Result<usize>> {
loop {
let ev = ready!(self.io.poll_read_ready(cx))?;
@@ -326,8 +318,10 @@ impl TcpStream {
///
/// [`read`]: fn@crate::io::AsyncReadExt::read
/// [`AsyncReadExt`]: trait@crate::io::AsyncReadExt
- pub async fn peek(&mut self, buf: &mut [u8]) -> io::Result<usize> {
- poll_fn(|cx| self.poll_peek(cx, buf)).await
+ pub async fn peek(&self, buf: &mut [u8]) -> io::Result<usize> {
+ self.io
+ .async_io(mio::Interest::READABLE, |io| io.peek(buf))
+ .await
}
/// Shuts down the read, write, or both halves of this connection.