pub struct OwnedWriteHalf { /* private fields */ }展开描述
TcpStream 的 owned 写半部,由 into_split 创建。
请注意,在此类型的 AsyncWrite 实现中,poll_shutdown 会在写方向上关闭 TCP 流。丢弃写半部也会在写方向上关闭 TCP 流。
向 OwnedWriteHalf 写入通常通过 AsyncWriteExt trait 上的便捷方法来完成。
实现§
Source§impl OwnedWriteHalf
impl OwnedWriteHalf
Sourcepub fn reunite(self, other: OwnedReadHalf) -> Result<TcpStream, ReuniteError>
pub fn reunite(self, other: OwnedReadHalf) -> Result<TcpStream, ReuniteError>
尝试将一个 TcpStream 的两半重新合并,并恢复原始的套接字。只有当这两半来自对 into_split 的同一次调用时才会成功。
Sourcepub 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。
§Cancel safety
此方法可安全取消。一旦就绪事件发生,该方法将持续立即返回,直到就绪事件被尝试进行读取或写入(且失败返回 WouldBlock 或 Poll::Pending)的操作消耗。
Sourcepub async fn writable(&self) -> Result<()>
pub async fn writable(&self) -> Result<()>
等待套接字变为可写。
该函数等同于 ready(Interest::WRITABLE),通常与 try_write() 配合使用。
§Cancel safety
此方法可安全取消。一旦就绪事件发生,该方法将持续立即返回,直到就绪事件被尝试进行写入(且失败返回 WouldBlock 或 Poll::Pending)的操作消耗。
Sourcepub fn try_write(&self, buf: &[u8]) -> Result<usize>
pub fn try_write(&self, buf: &[u8]) -> Result<usize>
尝试将一个缓冲区写入流,并返回已写入的字节数。
该函数会尝试写入 buf 的全部内容,但可能只会写入缓冲区的一部分。
该函数通常与 writable() 配合使用。
§Return
如果数据成功写入,则返回 Ok(n),其中 n 为已写入的字节数。如果流尚未准备好写入数据,则返回 Err(io::ErrorKind::WouldBlock)。
Sourcepub fn try_write_vectored(&self, bufs: &[IoSlice<'_>]) -> Result<usize>
pub fn try_write_vectored(&self, bufs: &[IoSlice<'_>]) -> Result<usize>
尝试将多个缓冲区写入流,返回写入的字节数。
数据从每个缓冲区依次写入,最后一个缓冲区可能仅被部分消费。此方法等效于对拼接后的缓冲区进行一次 try_write() 调用。
该函数通常与 writable() 配合使用。
§Return
如果数据成功写入,则返回 Ok(n),其中 n 为已写入的字节数。如果流尚未准备好写入数据,则返回 Err(io::ErrorKind::WouldBlock)。
Sourcepub fn peer_addr(&self) -> Result<SocketAddr>
pub fn peer_addr(&self) -> Result<SocketAddr>
返回该流连接到的远端地址。
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
返回该流绑定的本地地址。
Trait 实现§
Source§impl AsRef<TcpStream> for OwnedWriteHalf
impl AsRef<TcpStream> for OwnedWriteHalf
Source§impl AsyncWrite for OwnedWriteHalf
impl AsyncWrite for OwnedWriteHalf
Source§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. 更多信息Source§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. 更多信息Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
poll_write_vectored
implementation. 更多信息