Struct s2n_quic::stream::SendStream
source · pub struct SendStream(/* private fields */);
Expand description
A QUIC stream that is only allowed to send data.
Implementations§
source§impl SendStream
impl SendStream
sourcepub fn id(&self) -> u64
pub fn id(&self) -> u64
Returns the stream’s identifier
This value is unique to a particular connection. The format follows the same as what is defined in the QUIC Transport RFC.
§Examples
let stream = connection.open_send_stream().await?;
println!("New stream's id: {}", stream.id());
sourcepub fn connection(&self) -> Handle
pub fn connection(&self) -> Handle
Returns the connection::Handle
associated with the stream.
§Examples
let connection = stream.connection();
println!("The stream's connection id is: {}", connection.id());
sourcepub async fn send(&mut self, data: Bytes) -> Result<()>
pub async fn send(&mut self, data: Bytes) -> Result<()>
Enqueues a chunk of data for sending it towards the peer.
§Return value
The function returns:
Ok(())
if the data was enqueued for sending.Err(e)
if the stream encountered astream::Error
.
§Examples
let data = bytes::Bytes::from_static(&[1, 2, 3, 4]);
stream.send(data).await?;
sourcepub fn poll_send(
&mut self,
chunk: &mut Bytes,
cx: &mut Context<'_>
) -> Poll<Result<()>>
pub fn poll_send( &mut self, chunk: &mut Bytes, cx: &mut Context<'_> ) -> Poll<Result<()>>
Enqueues a chunk of data for sending it towards the peer.
§Return value
The function returns:
Poll::Pending
if the stream’s send buffer capacity is currently exhausted. In this case, the caller should retry sending after theWaker
on the providedContext
is notified.Poll::Ready(Ok(()))
if the data was enqueued for sending. The providedchunk
will be replaced with an emptyBytes
.Poll::Ready(Err(e))
if the stream encountered astream::Error
.
sourcepub async fn send_vectored(&mut self, chunks: &mut [Bytes]) -> Result<()>
pub async fn send_vectored(&mut self, chunks: &mut [Bytes]) -> Result<()>
Enqueues a slice of chunks of data for sending it towards the peer.
§Return value
The function returns:
Ok(())
if all of the chunks of data were enqueued for sending. Each of the consumedBytes
will be replaced with an emptyBytes
.Err(e)
if the stream encountered astream::Error
.
§Examples
let mut data1 = bytes::Bytes::from_static(&[1, 2, 3]);
let mut data2 = bytes::Bytes::from_static(&[4, 5, 6]);
let mut data3 = bytes::Bytes::from_static(&[7, 8, 9]);
let chunks = [data1, data2, data3];
stream.send_vectored(&mut chunks).await?;
sourcepub fn poll_send_vectored(
&mut self,
chunks: &mut [Bytes],
cx: &mut Context<'_>
) -> Poll<Result<usize>>
pub fn poll_send_vectored( &mut self, chunks: &mut [Bytes], cx: &mut Context<'_> ) -> Poll<Result<usize>>
Polls enqueueing a slice of chunks of data for sending it towards the peer.
§Return value
The function returns:
Poll::Pending
if the stream’s send buffer capacity is currently exhausted. In this case, the caller should retry sending after theWaker
on the providedContext
is notified.Poll::Ready(Ok(count))
if one or more chunks of data were enqueued for sending. Any of the consumedBytes
will be replaced with an emptyBytes
. Ifcount
does not equal the total number of chunks, the stream will store the Waker and notify the task once more capacity is available.Poll::Ready(Err(e))
if the stream encountered astream::Error
.
sourcepub fn poll_send_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<usize>>
pub fn poll_send_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<usize>>
Polls send readiness for the given stream.
This method must be called before calling send_data
.
§Return value
The function returns:
Poll::Pending
if the stream’s send buffer capacity is currently exhausted. In this case, the caller should retry sending after theWaker
on the providedContext
is notified.Poll::Ready(Ok(available_bytes))
if the stream is ready to send data, whereavailable_bytes
is how many bytes the stream can currently accept.Poll::Ready(Err(e))
if the stream encountered astream::Error
.
sourcepub fn send_data(&mut self, chunk: Bytes) -> Result<()>
pub fn send_data(&mut self, chunk: Bytes) -> Result<()>
Sends data on the stream without blocking the task.
poll_send_ready
must be called before calling this method.
§Return value
The function returns:
Ok(())
if the data was enqueued for sending.Err(SendingBlocked)
if the stream did not have enough capacity to enqueue thechunk
.Err(e)
if the stream encountered astream::Error
.
sourcepub async fn flush(&mut self) -> Result<()>
pub async fn flush(&mut self) -> Result<()>
Flushes the stream and waits for the peer to receive all outstanding data.
§Return value
The function returns:
Ok(())
if the send buffer was completely flushed and acknowledged by the peer.Err(e)
if the stream encountered astream::Error
.
§Examples
let data = bytes::Bytes::from_static(&[1, 2, 3, 4]);
stream.send(data).await?;
stream.flush().await?;
// at this point, the peer has received all of the `data`
sourcepub fn poll_flush(&mut self, cx: &mut Context<'_>) -> Poll<Result<()>>
pub fn poll_flush(&mut self, cx: &mut Context<'_>) -> Poll<Result<()>>
Polls flushing the stream and waits for the peer to receive all outstanding data.
§Return value
The function returns:
Poll::Pending
if the stream’s send buffer is still being sent. In this case, the caller should retry sending after theWaker
on the providedContext
is notified.Poll::Ready(Ok(()))
if the send buffer was completely flushed and acknowledged by the peer.Poll::Ready(Err(e))
if the stream encountered astream::Error
.
sourcepub fn finish(&mut self) -> Result<()>
pub fn finish(&mut self) -> Result<()>
Marks the stream as finished.
This method returns immediately without notifying the caller that all of the outstanding
data has been received by the peer. An application wanting to both finish
and flush
the outstanding data can use close
to accomplish
this.
NOTE: This method will be called when the stream
is dropped.
§Return value
The function returns:
Ok(())
if the stream was finished successfully.Err(e)
if the stream encountered astream::Error
.
sourcepub async fn close(&mut self) -> Result<()>
pub async fn close(&mut self) -> Result<()>
Marks the stream as finished and waits for all outstanding data to be acknowledged.
This method is equivalent to calling finish
and flush
.
§Return value
The function returns:
Ok(())
if the send buffer was completely flushed and acknowledged by the peer.Err(e)
if the stream encountered astream::Error
.
§Examples
let data = bytes::Bytes::from_static(&[1, 2, 3, 4]);
stream.send(data).await?;
stream.close().await?;
// at this point, the peer has received all of the `data` and has acknowledged the
// stream being finished.
sourcepub fn poll_close(&mut self, cx: &mut Context<'_>) -> Poll<Result<()>>
pub fn poll_close(&mut self, cx: &mut Context<'_>) -> Poll<Result<()>>
Marks the stream as finished and polls for all outstanding data to be acknowledged.
This method is equivalent to calling finish
and flush
.
§Return value
The function returns:
Poll::Pending
if the stream’s send buffer is still being sent. In this case, the caller should retry sending after theWaker
on the providedContext
is notified.Poll::Ready(Ok(()))
if the send buffer was completely flushed and acknowledged by the peer.Poll::Ready(Err(e))
if the stream encountered astream::Error
.
sourcepub fn reset(&mut self, error_code: Error) -> Result<()>
pub fn reset(&mut self, error_code: Error) -> Result<()>
Closes the stream with an error code.
After calling this, the stream is closed and will not accept any additional data to be sent to the peer. The peer will also be notified of the error code.
§Return value
The function returns:
Ok(())
if the stream was reset successfully.Err(e)
if the stream encountered astream::Error
. The stream may have been reset previously, or the connection itself was closed.
Trait Implementations§
source§impl AsyncWrite for SendStream
impl AsyncWrite for SendStream
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. Read moresource§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>>
bufs
into the object using vectored
IO operations. Read moresource§impl AsyncWrite for SendStream
impl AsyncWrite for SendStream
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. Read moresource§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. Read moresource§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
poll_write_vectored
implementation. Read moresource§impl Debug for SendStream
impl Debug for SendStream
source§impl From<SendStream> for LocalStream
impl From<SendStream> for LocalStream
source§fn from(stream: SendStream) -> Self
fn from(stream: SendStream) -> Self
source§impl From<SendStream> for Stream
impl From<SendStream> for Stream
source§fn from(stream: SendStream) -> Self
fn from(stream: SendStream) -> Self
source§impl Sink<Bytes> for SendStream
impl Sink<Bytes> for SendStream
§type Error = StreamError
type Error = StreamError
source§fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Sink
to receive a value. Read moresource§fn start_send(self: Pin<&mut Self>, data: Bytes) -> Result<()>
fn start_send(self: Pin<&mut Self>, data: Bytes) -> Result<()>
poll_ready
which returned Poll::Ready(Ok(()))
. Read moresource§impl SplittableStream for SendStream
impl SplittableStream for SendStream
source§fn split(self) -> (Option<ReceiveStream>, Option<SendStream>)
fn split(self) -> (Option<ReceiveStream>, Option<SendStream>)
Auto Trait Implementations§
impl Freeze for SendStream
impl !RefUnwindSafe for SendStream
impl Send for SendStream
impl Sync for SendStream
impl Unpin for SendStream
impl !UnwindSafe for SendStream
Blanket Implementations§
source§impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
source§fn flush(&mut self) -> Flush<'_, Self>where
Self: Unpin,
fn flush(&mut self) -> Flush<'_, Self>where
Self: Unpin,
AsyncWrite
. Read moresource§fn close(&mut self) -> Close<'_, Self>where
Self: Unpin,
fn close(&mut self) -> Close<'_, Self>where
Self: Unpin,
AsyncWrite
.source§fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>where
Self: Unpin,
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>where
Self: Unpin,
buf
into the object. Read moresource§fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectored<'a, Self>where
Self: Unpin,
fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectored<'a, Self>where
Self: Unpin,
bufs
into the object using vectored
IO operations. Read moresource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T, Item> SinkExt<Item> for T
impl<T, Item> SinkExt<Item> for T
source§fn with<U, Fut, F, E>(self, f: F) -> With<Self, Item, U, Fut, F>
fn with<U, Fut, F, E>(self, f: F) -> With<Self, Item, U, Fut, F>
source§fn with_flat_map<U, St, F>(self, f: F) -> WithFlatMap<Self, Item, U, St, F>
fn with_flat_map<U, St, F>(self, f: F) -> WithFlatMap<Self, Item, U, St, F>
source§fn sink_map_err<E, F>(self, f: F) -> SinkMapErr<Self, F>
fn sink_map_err<E, F>(self, f: F) -> SinkMapErr<Self, F>
source§fn sink_err_into<E>(self) -> SinkErrInto<Self, Item, E>
fn sink_err_into<E>(self) -> SinkErrInto<Self, Item, E>
Into
trait. Read moresource§fn buffer(self, capacity: usize) -> Buffer<Self, Item>where
Self: Sized,
fn buffer(self, capacity: usize) -> Buffer<Self, Item>where
Self: Sized,
source§fn flush(&mut self) -> Flush<'_, Self, Item>where
Self: Unpin,
fn flush(&mut self) -> Flush<'_, Self, Item>where
Self: Unpin,
source§fn send(&mut self, item: Item) -> Send<'_, Self, Item>where
Self: Unpin,
fn send(&mut self, item: Item) -> Send<'_, Self, Item>where
Self: Unpin,
source§fn feed(&mut self, item: Item) -> Feed<'_, Self, Item>where
Self: Unpin,
fn feed(&mut self, item: Item) -> Feed<'_, Self, Item>where
Self: Unpin,
source§fn send_all<'a, St>(&'a mut self, stream: &'a mut St) -> SendAll<'a, Self, St>
fn send_all<'a, St>(&'a mut self, stream: &'a mut St) -> SendAll<'a, Self, St>
source§fn right_sink<Si1>(self) -> Either<Si1, Self>
fn right_sink<Si1>(self) -> Either<Si1, Self>
source§fn poll_ready_unpin(
&mut self,
cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>where
Self: Unpin,
fn poll_ready_unpin(
&mut self,
cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>where
Self: Unpin,
Sink::poll_ready
on Unpin
sink types.source§fn start_send_unpin(&mut self, item: Item) -> Result<(), Self::Error>where
Self: Unpin,
fn start_send_unpin(&mut self, item: Item) -> Result<(), Self::Error>where
Self: Unpin,
Sink::start_send
on Unpin
sink types.