Expose SendStream::poll_write and poll_finish methods

This commit is contained in:
jean-airoldie
2024-03-16 16:56:02 -04:00
committed by Dirkjan Ochtman
parent ffac4a339c
commit 5dd70afc42
+25 -1
View File
@@ -138,7 +138,16 @@ impl SendStream {
Finish { stream: self }.await
}
#[doc(hidden)]
/// Attempt to shut down the send stream gracefully.
///
/// No new data may be written after calling this method. Completes when the peer has
/// acknowledged all sent data, retransmitting data as needed.
///
/// On success, return Poll::Ready(Ok(())).
///
/// If the stream is not ready for writing, the method returns Poll::Pending and arranges
/// for the current task (via cx.waker().wake_by_ref()) to receive a notification when the
/// stream becomes writable or is closed.
pub fn poll_finish(&mut self, cx: &mut Context) -> Poll<Result<(), WriteError>> {
let mut conn = self.conn.state.lock("poll_finish");
if self.is_0rtt {
@@ -242,6 +251,21 @@ impl SendStream {
pub fn id(&self) -> StreamId {
self.stream
}
/// Attempt to write bytes from buf into the stream.
///
/// On success, returns Poll::Ready(Ok(num_bytes_written)).
///
/// If the stream is not ready for writing, the method returns Poll::Pending and arranges
/// for the current task (via cx.waker().wake_by_ref()) to receive a notification when the
/// stream becomes writable or is closed.
pub fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &[u8],
) -> Poll<Result<usize, WriteError>> {
self.get_mut().execute_poll(cx, |stream| stream.write(buf))
}
}
#[cfg(feature = "futures-io")]