pub struct Stream<'a> { /* private fields */ }Expand description
Stream represents an SCTP stream
Implementations§
Source§impl Stream<'_>
impl Stream<'_>
Sourcepub fn read(&mut self) -> Result<Option<Chunks>>
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.
Sourcepub fn read_sctp(&mut self) -> Result<Option<Chunks>>
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.
Sourcepub fn read_part(&mut self) -> Result<Option<MessagePart>>
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.
Sourcepub fn in_partial_delivery(&self) -> bool
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.
Sourcepub fn write_sctp(
&mut self,
now: Instant,
p: &Bytes,
ppi: PayloadProtocolIdentifier,
) -> Result<usize>
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.
Sourcepub fn write_sctp_with_ppid(
&mut self,
now: Instant,
p: &Bytes,
ppid: u32,
) -> Result<usize>
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.
Sourcepub fn write(&mut self, now: Instant, data: &[u8]) -> Result<usize>
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.
Sourcepub fn write_with_ppi(
&mut self,
now: Instant,
data: &[u8],
ppi: PayloadProtocolIdentifier,
) -> Result<usize>
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.
Sourcepub fn write_chunk(&mut self, now: Instant, p: &Bytes) -> Result<usize>
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
Sourcepub fn write_chunk_with_ppi(
&mut self,
now: Instant,
data: &Bytes,
ppi: PayloadProtocolIdentifier,
) -> Result<usize>
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.
Sourcepub fn write_chunks(
&mut self,
now: Instant,
data: &mut [Bytes],
) -> Result<usize>
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.
Sourcepub fn is_readable(&self) -> bool
pub fn is_readable(&self) -> bool
Whether this stream has data or an error waiting to be read.
Sourcepub fn is_writable(&self) -> bool
pub fn is_writable(&self) -> bool
Whether this stream can currently accept more data.
Sourcepub fn stop(&mut self, now: Instant) -> Result<()>
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.
Sourcepub fn finish(&mut self) -> Result<()>
pub fn finish(&mut self) -> Result<()>
finish closes the write-direction of the stream. Future calls to write are not permitted after calling Close.
Sourcepub fn close(&mut self, now: Instant) -> Result<()>
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.
Sourcepub fn stream_identifier(&self) -> StreamId
pub fn stream_identifier(&self) -> StreamId
stream_identifier returns the Stream identifier associated to the stream.
Sourcepub fn set_priority(&mut self, priority: u16) -> Result<()>
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.
Sourcepub fn set_default_payload_type(
&mut self,
default_payload_type: PayloadProtocolIdentifier,
) -> Result<()>
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.
Sourcepub fn get_default_payload_type(&self) -> Result<PayloadProtocolIdentifier>
pub fn get_default_payload_type(&self) -> Result<PayloadProtocolIdentifier>
get_default_payload_type returns the payload type associated to the stream.
Sourcepub fn set_reliability_params(
&mut self,
unordered: bool,
rel_type: ReliabilityType,
rel_val: u32,
) -> Result<()>
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.
Sourcepub fn bytes_dequeued(&self) -> Result<u64>
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.
Sourcepub fn buffered_amount(&self) -> Result<usize>
pub fn buffered_amount(&self) -> Result<usize>
buffered_amount returns the number of bytes of data currently queued to be sent over this stream.
Sourcepub fn buffered_amount_low_threshold(&self) -> Result<usize>
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.
Sourcepub fn set_buffered_amount_low_threshold(&mut self, th: usize) -> Result<()>
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().
Sourcepub fn buffered_amount_high_threshold(&self) -> Result<usize>
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.
Sourcepub fn set_buffered_amount_high_threshold(&mut self, th: usize) -> Result<()>
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().