pub struct OwnedWriteHalf { /* 私有字段 */ }展开描述
TcpStream 的 owned 写半部,由 into_split 创建。
请注意,在此类型的 AsyncWrite 实现中,poll_shutdown 将关闭 TCP 流的写方向。Drop 写半部也会关闭 TCP 流的写半部。
写入 OwnedWriteHalf 通常使用 AsyncWriteExt trait 上提供的便捷方法来完成。
实现§
源代码§impl OwnedWriteHalf
impl OwnedWriteHalf
源代码pub fn reunite(self, other: OwnedReadHalf) -> Result<TcpStream, ReuniteError>
pub fn reunite(self, other: OwnedReadHalf) -> Result<TcpStream, ReuniteError>
尝试将 TcpStream 的两个半部分重新合并并恢复原始套接字。仅当两个半部分源自同一调用 into_split 时才会成功。
源代码pub async fn ready(&self, interest: Interest) -> Result<Ready>
pub async fn ready(&self, interest: Interest) -> Result<Ready>
等待任何所请求的就绪状态。
此函数通常与 try_write() 配合使用。它可以用来代替 writable(),以检查返回的就绪集中的 Ready::WRITABLE 和 Ready::WRITE_CLOSED 事件。
该函数可能在套接字尚未就绪时完成。这是一种误报,尝试进行操作将返回 io::ErrorKind::WouldBlock。该函数也可能返回空的 Ready 集合,因此应始终检查返回值,如果请求的状态未设置,可能需要再次等待。
此函数等价于 TcpStream::ready。
§取消安全性
此方法可安全取消。一旦就绪事件发生,该方法将继续立即返回,直到通过尝试读取或写入而消费该就绪事件(失败时返回 WouldBlock 或 Poll::Pending)。
源代码pub async fn writable(&self) -> Result<()>
pub async fn writable(&self) -> Result<()>
等待套接字变为可写。
此函数等价于 ready(Interest::WRITABLE),通常与 try_write() 配对使用。
§取消安全性
此方法可安全取消。一旦就绪事件发生,该方法将继续立即返回,直到通过尝试写入而消费该就绪事件(失败时返回 WouldBlock 或 Poll::Pending)。
源代码pub fn try_write(&self, buf: &[u8]) -> Result<usize>
pub fn try_write(&self, buf: &[u8]) -> Result<usize>
尝试将缓冲区写入流,返回写入的字节数。
该函数将尝试写入 buf 的全部内容,但缓冲区可能只有部分被写入。
此函数通常与 writable() 配对使用。
§返回值
如果成功写入数据,则返回 Ok(n),其中 n 是写入的字节数。如果流未准备好写入数据,则返回 Err(io::ErrorKind::WouldBlock)。
源代码pub fn try_write_vectored(&self, bufs: &[IoSlice<'_>]) -> Result<usize>
pub fn try_write_vectored(&self, bufs: &[IoSlice<'_>]) -> Result<usize>
尝试将多个缓冲区写入流,返回写入的字节数。
按顺序从每个缓冲区写入数据,最后读取的缓冲区可能只被部分使用。此方法的行为等效于使用串联缓冲区对 try_write() 进行单次调用。
此函数通常与 writable() 配对使用。
§返回值
如果成功写入数据,则返回 Ok(n),其中 n 是写入的字节数。如果流未准备好写入数据,则返回 Err(io::ErrorKind::WouldBlock)。
源代码pub fn peer_addr(&self) -> Result<SocketAddr>
pub fn peer_addr(&self) -> Result<SocketAddr>
返回此流连接到的远程地址。
源代码pub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
返回此流绑定的本地地址。
trait 实现§
源代码§impl AsRef<TcpStream> for OwnedWriteHalf
impl AsRef<TcpStream> for OwnedWriteHalf
源代码§impl AsyncWrite for OwnedWriteHalf
impl AsyncWrite for OwnedWriteHalf
源代码§fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize>>
fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>
buf into the object. 更多信息源代码§fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>],
) -> Poll<Result<usize>>
fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize>>
poll_write, except that it writes from a slice of buffers. 更多信息源代码§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
poll_write_vectored
implementation. 更多信息