Struct TcpStream

Source
pub struct TcpStream { /* private fields */ }
Expand description

TcpStream

Implementations§

Source§

impl TcpStream

Source

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.

Source

pub async fn connect_addr(addr: SocketAddr) -> Result<Self>

Establish a connection to the specified addr.

Source

pub async fn connect_addr_with_config( addr: SocketAddr, opts: &TcpConnectOpts, ) -> Result<Self>

Establish a connection to the specified addr with given config.

Source

pub fn local_addr(&self) -> Result<SocketAddr>

Return the local address that this stream is bound to.

Source

pub fn peer_addr(&self) -> Result<SocketAddr>

Return the remote address that this stream is connected to.

Source

pub fn nodelay(&self) -> Result<bool>

Get the value of the TCP_NODELAY option on this socket.

Source

pub fn set_nodelay(&self, nodelay: bool) -> Result<()>

Set the value of the TCP_NODELAY option on this socket.

Source

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.

Source

pub fn from_std(stream: TcpStream) -> Result<Self>

Creates new TcpStream from a std::net::TcpStream.

Source

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.

Source

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

Source

pub fn try_into_poll_io(self) -> Result<TcpStreamPoll, (Error, TcpStream)>

Convert to poll-io style TcpStreamPoll

Trait Implementations§

Source§

impl AsRawFd for TcpStream

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl AsReadFd for TcpStream

Source§

fn as_reader_fd(&mut self) -> &SharedFdWrapper

Get fd.
Source§

impl AsWriteFd for TcpStream

Source§

fn as_writer_fd(&mut self) -> &SharedFdWrapper

Get fd.
Source§

impl AsyncReadRent for TcpStream

Source§

fn read<T: IoBufMut>( &mut self, buf: T, ) -> impl Future<Output = BufResult<usize, T>>

Reads bytes from this source into the provided buffer, returning the number of bytes read. Read more
Source§

fn readv<T: IoVecBufMut>( &mut self, buf: T, ) -> impl Future<Output = BufResult<usize, T>>

Similar to read, but reads data into a slice of buffers. Read more
Source§

impl AsyncWriteRent for TcpStream

Source§

fn write<T: IoBuf>( &mut self, buf: T, ) -> impl Future<Output = BufResult<usize, T>>

Writes the contents of a buffer into this writer, returning the number of bytes written. Read more
Source§

fn writev<T: IoVecBuf>( &mut self, buf_vec: T, ) -> impl Future<Output = BufResult<usize, T>>

This function attempts to write the entire contents of 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 more
Source§

fn flush(&mut self) -> impl Future<Output = Result<()>>

Flushes this output stream, ensuring that all buffered content is successfully written to its destination. Read more
Source§

fn shutdown(&mut self) -> impl Future<Output = Result<()>>

Shuts down the output stream, ensuring that the value can be cleanly dropped. Read more
Source§

impl CancelableAsyncReadRent for TcpStream

Source§

async fn cancelable_read<T: IoBufMut>( &mut self, buf: T, c: CancelHandle, ) -> BufResult<usize, T>

Same as read(2)
Source§

async fn cancelable_readv<T: IoVecBufMut>( &mut self, buf: T, c: CancelHandle, ) -> BufResult<usize, T>

Same as readv(2)
Source§

impl CancelableAsyncWriteRent for TcpStream

Source§

async fn cancelable_write<T: IoBuf>( &mut self, buf: T, c: CancelHandle, ) -> BufResult<usize, T>

Same as write(2)
Source§

async fn cancelable_writev<T: IoVecBuf>( &mut self, buf_vec: T, c: CancelHandle, ) -> BufResult<usize, T>

Same as writev(2)
Source§

async fn cancelable_flush(&mut self, _c: CancelHandle) -> Result<()>

Flush buffered data if needed
Source§

fn cancelable_shutdown( &mut self, _c: CancelHandle, ) -> impl Future<Output = Result<()>>

Same as shutdown
Source§

impl Debug for TcpStream

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl IntoPollIo for TcpStream

Source§

type PollIo = TcpStreamPoll

The poll-based io type.
Source§

fn try_into_poll_io(self) -> Result<Self::PollIo, (Error, Self)>

Convert a completion-based io to a poll-based io(able to get comp_io back).
Source§

fn into_poll_io(self) -> Result<Self::PollIo>

Convert a completion-based io to a poll-based io.
Source§

impl IntoRawFd for TcpStream

Source§

fn into_raw_fd(self) -> RawFd

Consumes this object, returning the raw underlying file descriptor. Read more
Source§

impl Split for TcpStream

TcpStream is safe to split to two parts

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<A> AsyncReadRentExt for A
where A: AsyncReadRent + ?Sized,

Source§

async fn read_exact<T>(&mut self, buf: T) -> (Result<usize, Error>, T)
where T: IoBufMut + 'static,

Read until buf capacity is fulfilled
Source§

async fn read_vectored_exact<T>(&mut self, buf: T) -> (Result<usize, Error>, T)
where T: IoVecBufMut + 'static,

Readv until buf capacity is fulfilled
Source§

async fn read_u8(&mut self) -> Result<u8, Error>

Read number in async way
Source§

async fn read_u16(&mut self) -> Result<u16, Error>

Read number in async way
Source§

async fn read_u32(&mut self) -> Result<u32, Error>

Read number in async way
Source§

async fn read_u64(&mut self) -> Result<u64, Error>

Read number in async way
Source§

async fn read_u128(&mut self) -> Result<u16, Error>

Read number in async way
Source§

async fn read_i8(&mut self) -> Result<i8, Error>

Read number in async way
Source§

async fn read_i16(&mut self) -> Result<i16, Error>

Read number in async way
Source§

async fn read_i32(&mut self) -> Result<i32, Error>

Read number in async way
Source§

async fn read_i64(&mut self) -> Result<i64, Error>

Read number in async way
Source§

async fn read_i128(&mut self) -> Result<i128, Error>

Read number in async way
Source§

async fn read_f32(&mut self) -> Result<f32, Error>

Read number in async way
Source§

async fn read_f64(&mut self) -> Result<f64, Error>

Read number in async way
Source§

async fn read_u8_le(&mut self) -> Result<u8, Error>

Read number in async way
Source§

async fn read_u16_le(&mut self) -> Result<u16, Error>

Read number in async way
Source§

async fn read_u32_le(&mut self) -> Result<u32, Error>

Read number in async way
Source§

async fn read_u64_le(&mut self) -> Result<u64, Error>

Read number in async way
Source§

async fn read_u128_le(&mut self) -> Result<u128, Error>

Read number in async way
Source§

async fn read_i8_le(&mut self) -> Result<i8, Error>

Read number in async way
Source§

async fn read_i16_le(&mut self) -> Result<i16, Error>

Read number in async way
Source§

async fn read_i32_le(&mut self) -> Result<i32, Error>

Read number in async way
Source§

async fn read_i64_le(&mut self) -> Result<i64, Error>

Read number in async way
Source§

async fn read_i128_le(&mut self) -> Result<i128, Error>

Read number in async way
Source§

async fn read_f32_le(&mut self) -> Result<f32, Error>

Read number in async way
Source§

async fn read_f64_le(&mut self) -> Result<f64, Error>

Read number in async way
Source§

impl<A> AsyncWriteRentExt for A
where A: AsyncWriteRent + ?Sized,

Source§

async fn write_all<T>(&mut self, buf: T) -> (Result<usize, Error>, T)
where T: IoBuf + 'static,

Write all
Source§

async fn write_vectored_all<T>(&mut self, buf: T) -> (Result<usize, Error>, T)
where T: IoVecBuf + 'static,

Write vectored all
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<A> CancelableAsyncReadRentExt for A

Source§

async fn cancelable_read_exact<T>( &mut self, buf: T, c: CancelHandle, ) -> (Result<usize, Error>, T)
where T: IoBufMut + 'static,

Read until buf capacity is fulfilled
Source§

async fn cancelable_read_vectored_exact<T>( &mut self, buf: T, c: CancelHandle, ) -> (Result<usize, Error>, T)
where T: IoVecBufMut + 'static,

Readv until buf capacity is fulfilled
Source§

async fn cancelable_read_u8(&mut self, c: CancelHandle) -> Result<u8, Error>

Read number in async way
Source§

async fn cancelable_read_u16(&mut self, c: CancelHandle) -> Result<u16, Error>

Read number in async way
Source§

async fn cancelable_read_u32(&mut self, c: CancelHandle) -> Result<u32, Error>

Read number in async way
Source§

async fn cancelable_read_u64(&mut self, c: CancelHandle) -> Result<u64, Error>

Read number in async way
Source§

async fn cancelable_read_u128(&mut self, c: CancelHandle) -> Result<u128, Error>

Read number in async way
Source§

async fn cancelable_read_i8(&mut self, c: CancelHandle) -> Result<i8, Error>

Read number in async way
Source§

async fn cancelable_read_i16(&mut self, c: CancelHandle) -> Result<i16, Error>

Read number in async way
Source§

async fn cancelable_read_i32(&mut self, c: CancelHandle) -> Result<i32, Error>

Read number in async way
Source§

async fn cancelable_read_i64(&mut self, c: CancelHandle) -> Result<i64, Error>

Read number in async way
Source§

async fn cancelable_read_i128(&mut self, c: CancelHandle) -> Result<i128, Error>

Read number in async way
Source§

async fn cancelable_read_f32(&mut self, c: CancelHandle) -> Result<f32, Error>

Read number in async way
Source§

async fn cancelable_read_f64(&mut self, c: CancelHandle) -> Result<f64, Error>

Read number in async way
Source§

async fn cancelable_read_u8_le(&mut self, c: CancelHandle) -> Result<u8, Error>

Read number in async way
Source§

async fn cancelable_read_u16_le( &mut self, c: CancelHandle, ) -> Result<u16, Error>

Read number in async way
Source§

async fn cancelable_read_u32_le( &mut self, c: CancelHandle, ) -> Result<u32, Error>

Read number in async way
Source§

async fn cancelable_read_u64_le( &mut self, c: CancelHandle, ) -> Result<u64, Error>

Read number in async way
Source§

async fn cancelable_read_u128_le( &mut self, c: CancelHandle, ) -> Result<u128, Error>

Read number in async way
Source§

async fn cancelable_read_i8_le(&mut self, c: CancelHandle) -> Result<i8, Error>

Read number in async way
Source§

async fn cancelable_read_i16_le( &mut self, c: CancelHandle, ) -> Result<i16, Error>

Read number in async way
Source§

async fn cancelable_read_i32_le( &mut self, c: CancelHandle, ) -> Result<i32, Error>

Read number in async way
Source§

async fn cancelable_read_i64_le( &mut self, c: CancelHandle, ) -> Result<i64, Error>

Read number in async way
Source§

async fn cancelable_read_i128_le( &mut self, c: CancelHandle, ) -> Result<i128, Error>

Read number in async way
Source§

async fn cancelable_read_f32_le( &mut self, c: CancelHandle, ) -> Result<f32, Error>

Read number in async way
Source§

async fn cancelable_read_f64_le( &mut self, c: CancelHandle, ) -> Result<f64, Error>

Read number in async way
Source§

impl<A> CancelableAsyncWriteRentExt for A

Source§

async fn write_all<T>( &mut self, buf: T, c: CancelHandle, ) -> (Result<usize, Error>, T)
where T: IoBuf + 'static,

Write all
Source§

async fn write_vectored_all<T>( &mut self, buf: T, c: CancelHandle, ) -> (Result<usize, Error>, T)
where T: IoVecBuf + 'static,

Write all
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Splitable for T
where T: Split + AsyncWriteRent,

Source§

type OwnedRead = OwnedReadHalf<T>

Owned Read Split
Source§

type OwnedWrite = OwnedWriteHalf<T>

Owned Write Split
Source§

fn into_split( self, ) -> (<T as Splitable>::OwnedRead, <T as Splitable>::OwnedWrite)

Split into owned parts
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.