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

source

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());
source

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());
source

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 a stream::Error.
§Examples
let data = bytes::Bytes::from_static(&[1, 2, 3, 4]);
stream.send(data).await?;
source

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 the Waker on the provided Context is notified.
  • Poll::Ready(Ok(())) if the data was enqueued for sending. The provided chunk will be replaced with an empty Bytes.
  • Poll::Ready(Err(e)) if the stream encountered a stream::Error.
source

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 consumed Bytes will be replaced with an empty Bytes.
  • Err(e) if the stream encountered a stream::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?;
source

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 the Waker on the provided Context is notified.
  • Poll::Ready(Ok(count)) if one or more chunks of data were enqueued for sending. Any of the consumed Bytes will be replaced with an empty Bytes. If count 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 a stream::Error.
source

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 the Waker on the provided Context is notified.
  • Poll::Ready(Ok(available_bytes)) if the stream is ready to send data, where available_bytes is how many bytes the stream can currently accept.
  • Poll::Ready(Err(e)) if the stream encountered a stream::Error.
source

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 the chunk.
  • Err(e) if the stream encountered a stream::Error.
source

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 a stream::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`
source

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 the Waker on the provided Context 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 a stream::Error.
source

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 a stream::Error.
source

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 a stream::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.
source

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 the Waker on the provided Context 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 a stream::Error.
source

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 a stream::Error. The stream may have been reset previously, or the connection itself was closed.

Trait Implementations§

source§

impl AsyncWrite for SendStream

source§

fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8] ) -> Poll<Result<usize>>

Attempt to write bytes from buf into the object. Read more
source§

fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>] ) -> Poll<Result<usize>>

Attempt to write bytes from bufs into the object using vectored IO operations. Read more
source§

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Attempt to flush the object, ensuring that any buffered data reach their destination. Read more
source§

fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Attempt to close the object. Read more
source§

impl AsyncWrite for SendStream

source§

fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8] ) -> Poll<Result<usize>>

Attempt to write bytes from buf into the object. Read more
source§

fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>] ) -> Poll<Result<usize>>

Like poll_write, except that it writes from a slice of buffers. Read more
source§

fn is_write_vectored(&self) -> bool

Determines if this writer has an efficient poll_write_vectored implementation. Read more
source§

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Attempts to flush the object, ensuring that any buffered data reach their destination. Read more
source§

fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Initiates or attempts to shut down this writer, returning success when the I/O connection has completely shut down. Read more
source§

impl Debug for SendStream

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<SendStream> for LocalStream

source§

fn from(stream: SendStream) -> Self

Converts to this type from the input type.
source§

impl From<SendStream> for Stream

source§

fn from(stream: SendStream) -> Self

Converts to this type from the input type.
source§

impl Sink<Bytes> for SendStream

§

type Error = StreamError

The type of value produced by the sink when an error occurs.
source§

fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Attempts to prepare the Sink to receive a value. Read more
source§

fn start_send(self: Pin<&mut Self>, data: Bytes) -> Result<()>

Begin the process of sending a value to the sink. Each call to this function must be preceded by a successful call to poll_ready which returned Poll::Ready(Ok(())). Read more
source§

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Flush any remaining output from this sink. Read more
source§

fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Flush any remaining output and close this sink, if necessary. Read more
source§

impl SplittableStream for SendStream

source§

fn split(self) -> (Option<ReceiveStream>, Option<SendStream>)

Splits the stream into ReceiveStream and SendStream halves Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<W> AsyncWriteExt for W
where W: AsyncWrite + ?Sized,

source§

fn flush(&mut self) -> Flush<'_, Self>
where Self: Unpin,

Creates a future which will entirely flush this AsyncWrite. Read more
source§

fn close(&mut self) -> Close<'_, Self>
where Self: Unpin,

Creates a future which will entirely close this AsyncWrite.
source§

fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>
where Self: Unpin,

Creates a future which will write bytes from buf into the object. Read more
source§

fn write_vectored<'a>( &'a mut self, bufs: &'a [IoSlice<'a>] ) -> WriteVectored<'a, Self>
where Self: Unpin,

Creates a future which will write bytes from bufs into the object using vectored IO operations. Read more
source§

fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAll<'a, Self>
where Self: Unpin,

Write data into this object. Read more
source§

fn into_sink<Item>(self) -> IntoSink<Self, Item>
where Item: AsRef<[u8]>, Self: Sized,

Allow using an AsyncWrite as a Sink<Item: AsRef<[u8]>>. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, Item> SinkExt<Item> for T
where T: Sink<Item> + ?Sized,

source§

fn with<U, Fut, F, E>(self, f: F) -> With<Self, Item, U, Fut, F>
where F: FnMut(U) -> Fut, Fut: Future<Output = Result<Item, E>>, E: From<Self::Error>, Self: Sized,

Composes a function in front of the sink. Read more
source§

fn with_flat_map<U, St, F>(self, f: F) -> WithFlatMap<Self, Item, U, St, F>
where F: FnMut(U) -> St, St: Stream<Item = Result<Item, Self::Error>>, Self: Sized,

Composes a function in front of the sink. Read more
source§

fn sink_map_err<E, F>(self, f: F) -> SinkMapErr<Self, F>
where F: FnOnce(Self::Error) -> E, Self: Sized,

Transforms the error returned by the sink.
source§

fn sink_err_into<E>(self) -> SinkErrInto<Self, Item, E>
where Self: Sized, Self::Error: Into<E>,

Map this sink’s error to a different error type using the Into trait. Read more
source§

fn buffer(self, capacity: usize) -> Buffer<Self, Item>
where Self: Sized,

Adds a fixed-size buffer to the current sink. Read more
source§

fn close(&mut self) -> Close<'_, Self, Item>
where Self: Unpin,

Close the sink.
source§

fn fanout<Si>(self, other: Si) -> Fanout<Self, Si>
where Self: Sized, Item: Clone, Si: Sink<Item, Error = Self::Error>,

Fanout items to multiple sinks. Read more
source§

fn flush(&mut self) -> Flush<'_, Self, Item>
where Self: Unpin,

Flush the sink, processing all pending items. Read more
source§

fn send(&mut self, item: Item) -> Send<'_, Self, Item>
where Self: Unpin,

A future that completes after the given item has been fully processed into the sink, including flushing. Read more
source§

fn feed(&mut self, item: Item) -> Feed<'_, Self, Item>
where Self: Unpin,

A future that completes after the given item has been received by the sink. Read more
source§

fn send_all<'a, St>(&'a mut self, stream: &'a mut St) -> SendAll<'a, Self, St>
where St: TryStream<Ok = Item, Error = Self::Error> + Stream + Unpin + ?Sized, Self: Unpin,

A future that completes after the given stream has been fully processed into the sink, including flushing. Read more
source§

fn left_sink<Si2>(self) -> Either<Self, Si2>
where Si2: Sink<Item, Error = Self::Error>, Self: Sized,

Wrap this sink in an Either sink, making it the left-hand variant of that Either. Read more
source§

fn right_sink<Si1>(self) -> Either<Si1, Self>
where Si1: Sink<Item, Error = Self::Error>, Self: Sized,

Wrap this stream in an Either stream, making it the right-hand variant of that Either. Read more
source§

fn poll_ready_unpin( &mut self, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>
where Self: Unpin,

A convenience method for calling Sink::poll_ready on Unpin sink types.
source§

fn start_send_unpin(&mut self, item: Item) -> Result<(), Self::Error>
where Self: Unpin,

A convenience method for calling Sink::start_send on Unpin sink types.
source§

fn poll_flush_unpin( &mut self, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>
where Self: Unpin,

A convenience method for calling Sink::poll_flush on Unpin sink types.
source§

fn poll_close_unpin( &mut self, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>
where Self: Unpin,

A convenience method for calling Sink::poll_close on Unpin sink types.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T, U> Upcast<T> for U
where T: UpcastFrom<U>,

source§

fn upcast(self) -> T

source§

impl<T, B> UpcastFrom<Counter<T, B>> for T

source§

fn upcast_from(value: Counter<T, B>) -> T

source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V