Skip to content

Implement Read and Write on Arc<TcpStream> and Arc<UnixStream>. #134190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions library/std/src/net/tcp.rs
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ use crate::io::prelude::*;
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut};
use crate::iter::FusedIterator;
use crate::net::{Shutdown, SocketAddr, ToSocketAddrs};
use crate::sync::Arc;
use crate::sys_common::{AsInner, FromInner, IntoInner, net as net_imp};
use crate::time::Duration;

@@ -723,6 +724,47 @@ impl fmt::Debug for TcpStream {
}
}

#[stable(feature = "io_traits_arc_more", since = "CURRENT_RUSTC_VERSION")]
impl Read for Arc<TcpStream> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
(&**self).read(buf)
}

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> {
(&**self).read_buf(buf)
}

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
(&**self).read_vectored(bufs)
}

#[inline]
fn is_read_vectored(&self) -> bool {
(&**self).is_read_vectored()
}
}

#[stable(feature = "io_traits_arc_more", since = "CURRENT_RUSTC_VERSION")]
impl Write for Arc<TcpStream> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
(&**self).write(buf)
}

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
(&**self).write_vectored(bufs)
}

#[inline]
fn is_write_vectored(&self) -> bool {
(&**self).is_write_vectored()
}

#[inline]
fn flush(&mut self) -> io::Result<()> {
(&**self).flush()
}
}

impl TcpListener {
/// Creates a new `TcpListener` which will be bound to the specified
/// address.
42 changes: 42 additions & 0 deletions library/std/src/os/unix/net/stream.rs
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ use crate::net::Shutdown;
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
use crate::path::Path;
use crate::sealed::Sealed;
use crate::sync::Arc;
use crate::sys::cvt;
use crate::sys::net::Socket;
use crate::sys_common::{AsInner, FromInner};
@@ -649,6 +650,47 @@ impl<'a> io::Write for &'a UnixStream {
}
}

#[stable(feature = "io_traits_arc_more", since = "CURRENT_RUSTC_VERSION")]
impl io::Read for Arc<UnixStream> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
(&**self).read(buf)
}

fn read_buf(&mut self, buf: io::BorrowedCursor<'_>) -> io::Result<()> {
(&**self).read_buf(buf)
}

fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> {
(&**self).read_vectored(bufs)
}

#[inline]
fn is_read_vectored(&self) -> bool {
(&**self).is_read_vectored()
}
}

#[stable(feature = "io_traits_arc_more", since = "CURRENT_RUSTC_VERSION")]
impl io::Write for Arc<UnixStream> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
(&**self).write(buf)
}

fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
(&**self).write_vectored(bufs)
}

#[inline]
fn is_write_vectored(&self) -> bool {
(&**self).is_write_vectored()
}

#[inline]
fn flush(&mut self) -> io::Result<()> {
(&**self).flush()
}
}

#[stable(feature = "unix_socket", since = "1.10.0")]
impl AsRawFd for UnixStream {
#[inline]