pub struct TcpStream(/* private fields */);Expand description
A TCP stream between a local and a remote socket.
A TCP Stream can either be created by connecting to an endpoint, via the TcpStream::connect method,
or by super::TcpListener::accepting a connection from a super::TcpListener.
Reading and writing to a TcpStream is usually done by using the crate::io::Read and crate::io::Write traits.
Implementations§
Source§impl TcpStream
impl TcpStream
Sourcepub async fn connect(addr: SocketAddr) -> Result<TcpStream>
pub async fn connect(addr: SocketAddr) -> Result<TcpStream>
Opens a TCP connection to a remote host at the specified address.
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Returns the local address that this stream is bound to.
Sourcepub fn take_error(&self) -> Result<Option<Error>>
pub fn take_error(&self) -> Result<Option<Error>>
Returns the value of the SO_ERROR option.
Sourcepub fn peer_addr(&self) -> Result<SocketAddr>
pub fn peer_addr(&self) -> Result<SocketAddr>
Returns the remote address that this stream is connected to.
Sourcepub fn set_nodelay(&self, nodelay: bool) -> Result<()>
pub fn set_nodelay(&self, nodelay: bool) -> Result<()>
Sets the value of the TCP_NODELAY option on this socket.
Trait Implementations§
Source§impl AsFd for TcpStream
impl AsFd for TcpStream
Source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Borrows the file descriptor. Read more
Source§impl Read for TcpStream
impl Read for TcpStream
Source§async fn read(&mut self, buf: &mut [u8]) -> Result<usize>
async fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Reads data from the stream into the provided buffer.
fn read_vectored( &mut self, bufs: &mut [IoSliceMut<'_>], ) -> impl Future<Output = Result<usize>>
fn is_read_vectored(&self) -> bool
fn read_to_end( &mut self, buf: &mut Vec<u8>, ) -> impl Future<Output = Result<usize>>
fn read_to_string(&mut self) -> impl Future<Output = Result<String>>
fn read_exact(&mut self, buf: &mut [u8]) -> impl Future<Output = Result<()>>
Source§impl Unwrap for TcpStream
impl Unwrap for TcpStream
type StdImpl = TcpStream
type TokioImpl = TcpStream
Source§fn unwrap_std(self) -> Self::StdImpl
fn unwrap_std(self) -> Self::StdImpl
Unwraps the std underlying implementation of the MaybeFut type.
Source§fn unwrap_tokio(self) -> Self::TokioImpl
fn unwrap_tokio(self) -> Self::TokioImpl
Unwraps the tokio underlying implementation of the MaybeFut type.
Source§fn unwrap_std_ref(&self) -> &Self::StdImpl
fn unwrap_std_ref(&self) -> &Self::StdImpl
Unwraps the std underlying implementation of the MaybeFut type as a reference.
Source§fn unwrap_tokio_ref(&self) -> &Self::TokioImpl
fn unwrap_tokio_ref(&self) -> &Self::TokioImpl
Unwraps the tokio underlying implementation of the MaybeFut type as a reference.
Source§fn unwrap_std_mut(&mut self) -> &mut Self::StdImpl
fn unwrap_std_mut(&mut self) -> &mut Self::StdImpl
Unwraps the std underlying implementation of the MaybeFut type as a mutable reference.
Source§fn unwrap_tokio_mut(&mut self) -> &mut Self::TokioImpl
fn unwrap_tokio_mut(&mut self) -> &mut Self::TokioImpl
Unwraps the tokio underlying implementation of the MaybeFut type as a mutable reference.
Source§fn get_std(self) -> Option<Self::StdImpl>
fn get_std(self) -> Option<Self::StdImpl>
Safely unwraps the std underlying implementation of the MaybeFut type.
Source§fn get_tokio(self) -> Option<Self::TokioImpl>
fn get_tokio(self) -> Option<Self::TokioImpl>
Safely unwraps the tokio underlying implementation of the MaybeFut type.
Source§fn get_std_ref(&self) -> Option<&Self::StdImpl>
fn get_std_ref(&self) -> Option<&Self::StdImpl>
Safely unwraps the std underlying implementation of the MaybeFut type as a reference.
Source§fn get_tokio_ref(&self) -> Option<&Self::TokioImpl>
fn get_tokio_ref(&self) -> Option<&Self::TokioImpl>
Safely unwraps the tokio underlying implementation of the MaybeFut type as a reference.
Source§fn get_std_mut(&mut self) -> Option<&mut Self::StdImpl>
fn get_std_mut(&mut self) -> Option<&mut Self::StdImpl>
Safely unwraps the std underlying implementation of the MaybeFut type as a mutable reference.
Source§fn get_tokio_mut(&mut self) -> Option<&mut Self::TokioImpl>
fn get_tokio_mut(&mut self) -> Option<&mut Self::TokioImpl>
Safely unwraps the tokio underlying implementation of the MaybeFut type as a mutable reference.
Source§impl Write for TcpStream
impl Write for TcpStream
Source§async fn write(&mut self, buf: &[u8]) -> Result<usize>
async fn write(&mut self, buf: &[u8]) -> Result<usize>
Writes a buffer into this writer, returning how many bytes were successfully written.
Source§async fn flush(&mut self) -> Result<()>
async fn flush(&mut self) -> Result<()>
Flushes the output streamer, ensuring that all intermediately buffered contents reach their destination.
Auto Trait Implementations§
impl Freeze for TcpStream
impl RefUnwindSafe for TcpStream
impl Send for TcpStream
impl Sync for TcpStream
impl Unpin for TcpStream
impl UnwindSafe for TcpStream
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more