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
impl TcpStream
Sourcepub fn connect(addr: &str) -> ConnectFuture ⓘ
pub fn connect(addr: &str) -> ConnectFuture ⓘ
Sourcepub fn read<'a, 'b>(&'a mut self, buf: &'b mut [u8]) -> ReadFuture<'a, 'b> ⓘ
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。
Sourcepub fn write_all<'a, 'b>(&'a mut self, buf: &'b [u8]) -> WriteAllFuture<'a, 'b> ⓘ
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. 将持续写入,直到所有字节都已写入或发生错误。
Sourcepub fn split(&mut self) -> (ReadHalf<'_>, WriteHalf<'_>)
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。 调用者必须协调读/写操作。