pub struct TcpStream { /* private fields */ }
Expand description
TcpStream
Implementations§
Source§impl TcpStream
impl TcpStream
Sourcepub async fn connect<A: ToSocketAddrs>(addr: A) -> Result<Self>
pub async fn connect<A: ToSocketAddrs>(addr: A) -> Result<Self>
Open a TCP connection to a remote host. Note: This function may block the current thread while resolution is performed.
Sourcepub async fn connect_addr(addr: SocketAddr) -> Result<Self>
pub async fn connect_addr(addr: SocketAddr) -> Result<Self>
Establish a connection to the specified addr
.
Sourcepub async fn connect_addr_with_config(
addr: SocketAddr,
opts: &TcpConnectOpts,
) -> Result<Self>
pub async fn connect_addr_with_config( addr: SocketAddr, opts: &TcpConnectOpts, ) -> Result<Self>
Establish a connection to the specified addr
with given config.
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Return the local address that this stream is bound to.
Sourcepub fn peer_addr(&self) -> Result<SocketAddr>
pub fn peer_addr(&self) -> Result<SocketAddr>
Return 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<()>
Set the value of the TCP_NODELAY
option on this socket.
Sourcepub fn set_tcp_keepalive(
&self,
time: Option<Duration>,
interval: Option<Duration>,
retries: Option<u32>,
) -> Result<()>
pub fn set_tcp_keepalive( &self, time: Option<Duration>, interval: Option<Duration>, retries: Option<u32>, ) -> Result<()>
Set the value of the SO_KEEPALIVE
option on this socket.
Sourcepub fn from_std(stream: TcpStream) -> Result<Self>
pub fn from_std(stream: TcpStream) -> Result<Self>
Creates new TcpStream
from a std::net::TcpStream
.
Sourcepub async fn readable(&self, relaxed: bool) -> Result<()>
pub async fn readable(&self, relaxed: bool) -> Result<()>
Wait for read readiness. Note: Do not use it before every io. It is different from other runtimes!
Everytime call to this method may pay a syscall cost. In uring impl, it will push a PollAdd op; in epoll impl, it will use use inner readiness state; if !relaxed, it will call syscall poll after that.
If relaxed, on legacy driver it may return false positive result. If you want to do io by your own, you must maintain io readiness and wait for io ready with relaxed=false.
Sourcepub async fn writable(&self, relaxed: bool) -> Result<()>
pub async fn writable(&self, relaxed: bool) -> Result<()>
Wait for write readiness. Note: Do not use it before every io. It is different from other runtimes!
Everytime call to this method may pay a syscall cost. In uring impl, it will push a PollAdd op; in epoll impl, it will use use inner readiness state; if !relaxed, it will call syscall poll after that.
If relaxed, on legacy driver it may return false positive result. If you want to do io by your own, you must maintain io readiness and wait for io ready with relaxed=false.
Source§impl TcpStream
impl TcpStream
Sourcepub fn try_into_poll_io(self) -> Result<TcpStreamPoll, (Error, TcpStream)>
pub fn try_into_poll_io(self) -> Result<TcpStreamPoll, (Error, TcpStream)>
Convert to poll-io style TcpStreamPoll
Trait Implementations§
Source§impl AsReadFd for TcpStream
impl AsReadFd for TcpStream
Source§fn as_reader_fd(&mut self) -> &SharedFdWrapper
fn as_reader_fd(&mut self) -> &SharedFdWrapper
Source§impl AsWriteFd for TcpStream
impl AsWriteFd for TcpStream
Source§fn as_writer_fd(&mut self) -> &SharedFdWrapper
fn as_writer_fd(&mut self) -> &SharedFdWrapper
Source§impl AsyncReadRent for TcpStream
impl AsyncReadRent for TcpStream
Source§impl AsyncWriteRent for TcpStream
impl AsyncWriteRent for TcpStream
Source§fn write<T: IoBuf>(
&mut self,
buf: T,
) -> impl Future<Output = BufResult<usize, T>>
fn write<T: IoBuf>( &mut self, buf: T, ) -> impl Future<Output = BufResult<usize, T>>
Source§fn writev<T: IoVecBuf>(
&mut self,
buf_vec: T,
) -> impl Future<Output = BufResult<usize, T>>
fn writev<T: IoVecBuf>( &mut self, buf_vec: T, ) -> impl Future<Output = BufResult<usize, T>>
buf_vec
, but the write may not
fully succeed, and it might also result in an error. The bytes will be written starting at
the specified offset. Read moreSource§impl CancelableAsyncReadRent for TcpStream
impl CancelableAsyncReadRent for TcpStream
Source§async fn cancelable_read<T: IoBufMut>(
&mut self,
buf: T,
c: CancelHandle,
) -> BufResult<usize, T>
async fn cancelable_read<T: IoBufMut>( &mut self, buf: T, c: CancelHandle, ) -> BufResult<usize, T>
Source§async fn cancelable_readv<T: IoVecBufMut>(
&mut self,
buf: T,
c: CancelHandle,
) -> BufResult<usize, T>
async fn cancelable_readv<T: IoVecBufMut>( &mut self, buf: T, c: CancelHandle, ) -> BufResult<usize, T>
Source§impl CancelableAsyncWriteRent for TcpStream
impl CancelableAsyncWriteRent for TcpStream
Source§async fn cancelable_write<T: IoBuf>(
&mut self,
buf: T,
c: CancelHandle,
) -> BufResult<usize, T>
async fn cancelable_write<T: IoBuf>( &mut self, buf: T, c: CancelHandle, ) -> BufResult<usize, T>
Source§async fn cancelable_writev<T: IoVecBuf>(
&mut self,
buf_vec: T,
c: CancelHandle,
) -> BufResult<usize, T>
async fn cancelable_writev<T: IoVecBuf>( &mut self, buf_vec: T, c: CancelHandle, ) -> BufResult<usize, T>
Source§async fn cancelable_flush(&mut self, _c: CancelHandle) -> Result<()>
async fn cancelable_flush(&mut self, _c: CancelHandle) -> Result<()>
Source§fn cancelable_shutdown(
&mut self,
_c: CancelHandle,
) -> impl Future<Output = Result<()>>
fn cancelable_shutdown( &mut self, _c: CancelHandle, ) -> impl Future<Output = Result<()>>
Source§impl IntoPollIo for TcpStream
impl IntoPollIo for TcpStream
Source§type PollIo = TcpStreamPoll
type PollIo = TcpStreamPoll
Source§fn try_into_poll_io(self) -> Result<Self::PollIo, (Error, Self)>
fn try_into_poll_io(self) -> Result<Self::PollIo, (Error, Self)>
Source§fn into_poll_io(self) -> Result<Self::PollIo>
fn into_poll_io(self) -> Result<Self::PollIo>
Source§impl IntoRawFd for TcpStream
impl IntoRawFd for TcpStream
Source§fn into_raw_fd(self) -> RawFd
fn into_raw_fd(self) -> RawFd
impl Split for TcpStream
TcpStream is safe to split to two parts