Skip to main content

Stream

Struct Stream 

Source
pub struct Stream<'a> { /* private fields */ }
Expand description

Stream represents an SCTP stream

Implementations§

Source§

impl Stream<'_>

Source

pub fn read(&mut self) -> Result<Option<Chunks>>

read reads a packet of len(p) bytes, dropping the Payload Protocol Identifier. Returns EOF when the stream is reset or an error if the stream is closed otherwise.

Source

pub fn read_sctp(&mut self) -> Result<Option<Chunks>>

read_sctp reads a packet of len(p) bytes and returns the associated Payload Protocol Identifier. Returns EOF when the stream is reset or an error if the stream is closed otherwise.

Source

pub fn read_part(&mut self) -> Result<Option<MessagePart>>

Reads the next part of a message: the partial delivery API of RFC 9260 section 6.9 (the RECEIVE primitive with its “partial flag”, 11.1.7; RFC 6458 MSG_EOR).

A complete message comes whole, as one part with end_of_record set, just as read_sctp gives it. A message that has not all arrived is given out in parts once the fragments of it held from the first on come to the partial delivery point (TransportConfig::with_partial_delivery_point), or whatever their size when the receive buffer is out of space (a window that would be advertised as closed, with nothing readable whole). Its first part has first set, and its last end_of_record; until then nothing else of this stream is read, by either method. What is read leaves the receive buffer at once, and a window that was closed is announced open again (RFC 9260 6.2).

Without this, a message larger than the receive buffer, or interleaved messages (RFC 8260) that fill it together, cannot arrive under the rule of RFC 9260 section 6.2 (“When the receiver’s advertised window is 0, the receiver MUST drop any new incoming DATA chunk with a TSN larger than the largest TSN received so far”).

Returns Ok(None) when the stream has nothing to read in this way, and an error if the stream is closed.

Source

pub fn in_partial_delivery(&self) -> bool

Whether a message of this stream is being read in parts: its first part was read with read_part and its last not yet.

Source

pub fn write_sctp( &mut self, now: Instant, p: &Bytes, ppi: PayloadProtocolIdentifier, ) -> Result<usize>

write_sctp writes len(p) bytes from p to the DTLS connection

now is the instant the message is handed to the stack. See the note on Stream for why it is a parameter.

Source

pub fn write_sctp_with_ppid( &mut self, now: Instant, p: &Bytes, ppid: u32, ) -> Result<usize>

Sends a message with any Payload Protocol Identifier (RFC 9260 section 3.3.1: the value is the application’s and SCTP passes it through unchanged). The receiver reads it from Chunks::ppid.

PayloadProtocolIdentifier names only the WebRTC values; this takes the number.

Source

pub fn write(&mut self, now: Instant, data: &[u8]) -> Result<usize>

Send data on the given stream.

Uses the deafult payload protocol (PPI).

Returns the number of bytes successfully written.

Source

pub fn write_with_ppi( &mut self, now: Instant, data: &[u8], ppi: PayloadProtocolIdentifier, ) -> Result<usize>

Send data on the given stream, with a specific payload protocol.

Returns the number of bytes successfully written.

Source

pub fn write_chunk(&mut self, now: Instant, p: &Bytes) -> Result<usize>

write writes len(p) bytes from p with the default Payload Protocol Identifier

Source

pub fn write_chunk_with_ppi( &mut self, now: Instant, data: &Bytes, ppi: PayloadProtocolIdentifier, ) -> Result<usize>

Send an owned Bytes on the stream with a specific payload protocol.

Unlike write_with_ppi, which takes a &[u8] and must copy it into a freshly allocated buffer, this enqueues the payload zero-copy: each fragment is a refcounted slice of data. Prefer this on the hot send path when the caller already owns the payload as Bytes.

Returns the number of bytes successfully written.

Source

pub fn write_chunks( &mut self, now: Instant, data: &mut [Bytes], ) -> Result<usize>

Send data on the given stream

Returns the number of bytes and chunks successfully written. Note that this method might also write a partial chunk. In this case it will not count this chunk as fully written. However the chunk will be advanced and contain only non-written data after the call.

Source

pub fn is_readable(&self) -> bool

Whether this stream has data or an error waiting to be read.

Source

pub fn is_writable(&self) -> bool

Whether this stream can currently accept more data.

Source

pub fn stop(&mut self, now: Instant) -> Result<()>

stop closes the read-direction of the stream. Future calls to read are not permitted after calling stop.

now is the instant the caller is acting at: resetting the stream queues an outgoing chunk, so it is on the same write path as write_sctp.

Source

pub fn finish(&mut self) -> Result<()>

finish closes the write-direction of the stream. Future calls to write are not permitted after calling Close.

Source

pub fn close(&mut self, now: Instant) -> Result<()>

Shuts down the read, write, or both halves of this stream.

This function will cause all pending and future I/O on the specified portions to return immediately with an appropriate value (see the documentation of Shutdown).

Resets the stream when both halves of this stream are shutdown.

Source

pub fn stream_identifier(&self) -> StreamId

stream_identifier returns the Stream identifier associated to the stream.

Source

pub fn set_priority(&mut self, priority: u16) -> Result<()>

Sets this stream’s priority, in data channel priority units (RFC 8832 section 5.1: 128 below normal, 256 normal, 512 high, 1024 extra high; any value is taken). The default is 256.

It is the input of two stream schedulers: under WeightedFairQueueing it is the stream’s weight (a stream with n times the priority gets n times the capacity, RFC 8260 section 3.6), under Priority its rank (the higher value is served first, section 3.4). The other schedulers do not look at it. It applies from the next scheduling decision on, to what the stream has queued too, and lasts until the stream is reset.

RFC 8831 section 6.4 has a data channel’s priority drive the scheduler: the data channel layer calls this with the priority of the channel (from RTCDataChannelInit or the DATA_CHANNEL_OPEN message) when it opens or accepts the stream.

Source

pub fn set_default_payload_type( &mut self, default_payload_type: PayloadProtocolIdentifier, ) -> Result<()>

set_default_payload_type sets the default payload type used by write.

Source

pub fn get_default_payload_type(&self) -> Result<PayloadProtocolIdentifier>

get_default_payload_type returns the payload type associated to the stream.

Source

pub fn set_reliability_params( &mut self, unordered: bool, rel_type: ReliabilityType, rel_val: u32, ) -> Result<()>

set_reliability_params sets reliability parameters for this stream.

Source

pub fn bytes_dequeued(&self) -> Result<u64>

Application bytes of this stream that have left the send queue (transmitted, or abandoned before their first transmission): W3C bufferedAmount decreases by what “the underlying data transport sends … from its queue”, not by what the peer acknowledges.

Source

pub fn buffered_amount(&self) -> Result<usize>

buffered_amount returns the number of bytes of data currently queued to be sent over this stream.

Source

pub fn buffered_amount_low_threshold(&self) -> Result<usize>

buffered_amount_low_threshold returns the number of bytes of buffered outgoing data that is considered “low” Defaults to 0.

Source

pub fn set_buffered_amount_low_threshold(&mut self, th: usize) -> Result<()>

set_buffered_amount_low_threshold is used to update the threshold. See buffered_amount_low_threshold().

Source

pub fn buffered_amount_high_threshold(&self) -> Result<usize>

buffered_amount_high_threshold returns the number of bytes of buffered outgoing data that is considered “high” Defaults to u32::MAX.

Source

pub fn set_buffered_amount_high_threshold(&mut self, th: usize) -> Result<()>

set_buffered_amount_high_threshold is used to update the threshold. See buffered_amount_high_threshold().

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Stream<'a>

§

impl<'a> !UnwindSafe for Stream<'a>

§

impl<'a> Forget for Stream<'a>

§

impl<'a> Freeze for Stream<'a>
where &'a mut Association: Freeze,

§

impl<'a> Move for Stream<'a>

§

impl<'a> Send for Stream<'a>
where RawTable<(u32, ChunkReconfig)>: Send, RawVecInner: Send, RawTable<(u32, ParamOutgoingResetRequest)>: Send, BoxRaw<dyn Param>: Send, RawTable<(u32, IncomingResetWaiting)>: Send, Bytes: Send, NonZero<u64>: Send, Arc<CookieSigner>: Send, Arc<TransportConfig>: Send, Arc<dyn RTCCryptoProvider>: Send, RawTable<(u32, ChunkPayloadData)>: Send, RawTable<(MessageId, MessageTsns)>: Send, RawTable<(u16, StreamQueue)>: Send, RawTable<(u16, u16)>: Send, NodeRef<Owned, ((u128, u64), u16), SetValZST, LeafOrInternal>: Send, BoxRaw<(((u128, u64), u16), SetValZST)>: Send, NodeRef<Owned, (u64, u16), SetValZST, LeafOrInternal>: Send, BoxRaw<((u64, u16), SetValZST)>: Send, RawTable<(u16, ())>: Send, BoxRaw<dyn Chunk>: Send, RawTable<((u16, bool), u32)>: Send, RawTable<(u16, StreamState)>: Send, RawTable<(u16, u64)>: Send, Arc<Atomic<bool>>: Send,

§

impl<'a> Sync for Stream<'a>
where RawTable<(u32, ChunkReconfig)>: Sync, RawVecInner: Sync, RawTable<(u32, ParamOutgoingResetRequest)>: Sync, BoxRaw<dyn Param>: Sync, RawTable<(u32, IncomingResetWaiting)>: Sync, Bytes: Sync, NonZero<u64>: Sync, Arc<CookieSigner>: Sync, Arc<TransportConfig>: Sync, Arc<dyn RTCCryptoProvider>: Sync, RawTable<(u32, ChunkPayloadData)>: Sync, RawTable<(MessageId, MessageTsns)>: Sync, RawTable<(u16, StreamQueue)>: Sync, RawTable<(u16, u16)>: Sync, NodeRef<Owned, ((u128, u64), u16), SetValZST, LeafOrInternal>: Sync, BoxRaw<(((u128, u64), u16), SetValZST)>: Sync, NodeRef<Owned, (u64, u16), SetValZST, LeafOrInternal>: Sync, BoxRaw<((u64, u16), SetValZST)>: Sync, RawTable<(u16, ())>: Sync, BoxRaw<dyn Chunk>: Sync, RawTable<((u16, bool), u32)>: Sync, RawTable<(u16, StreamState)>: Sync, RawTable<(u16, u64)>: Sync, Arc<Atomic<bool>>: Sync,

§

impl<'a> Unpin for Stream<'a>
where &'a mut Association: Unpin,

§

impl<'a> UnsafeUnpin for Stream<'a>
where &'a mut Association: UnsafeUnpin,

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.