Skip to main content

TcpStream

Struct TcpStream 

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

A TCP stream between a local and a remote socket 本地套接字和远程套接字之间的TCP流

Provides async read/write operations with the underlying driver. 使用底层驱动提供异步读/写操作。

Implementations§

Source§

impl TcpStream

Source

pub fn connect(addr: &str) -> ConnectFuture

Connect to a remote address 连接到远程地址

§Example / 示例
use hiver_runtime::io::TcpStream;

async fn connect() -> std::io::Result<()> {
    let stream = TcpStream::connect("127.0.0.1:8080").await?;
    Ok(())
}
Source

pub fn read<'a, 'b>(&'a mut self, buf: &'b mut [u8]) -> ReadFuture<'a, 'b>

Read some bytes from the stream 从流中读取一些字节

Returns the number of bytes read. May return 0 if the stream is closed. 返回读取的字节数。如果流已关闭,可能返回0。

Source

pub fn write_all<'a, 'b>(&'a mut self, buf: &'b [u8]) -> WriteAllFuture<'a, 'b>

Write all bytes to the stream 将所有字节写入流

This will keep writing until all bytes have been written or an error occurs. 将持续写入,直到所有字节都已写入或发生错误。

Source

pub fn split(&mut self) -> (ReadHalf<'_>, WriteHalf<'_>)

Split the stream into read and write halves 将流拆分为读写两半

Note: This is a placeholder. The actual implementation will use Arc-based splitting like Tokio for true split read/write. 注意:这是占位符。实际实现将使用类似Tokio的基于Arc的拆分来实现真正的读写分离。

§Note / 注意

This is a simplified split implementation. Both halves reference the same underlying socket. The caller must coordinate read/write operations. 这是简化的 split 实现。两个半部引用同一个底层 socket。 调用者必须协调读/写操作。

Source

pub fn shutdown(&self, how: Shutdown) -> Result<()>

Shutdown the stream 关闭流

Trait Implementations§

Source§

impl AsRawFd for TcpStream

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more

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<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<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, 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.