FlowControl

Trait FlowControl 

Source
pub trait FlowControl: Send {
    // Required methods
    fn on_data_received(&mut self, channel_id: ChannelId, bytes: u32);
    fn wait_for_send_credit(
        &mut self,
        channel_id: ChannelId,
        bytes: u32,
    ) -> impl Future<Output = Result<()>> + Send;
    fn consume_send_credit(&mut self, channel_id: ChannelId, bytes: u32);
}
Expand description

Abstraction for stream flow control mechanism.

Different transports implement credit-based flow control differently:

  • Stream transports (TCP, WebSocket): explicit Message::Credit on the wire
  • SHM: shared atomic counters in the channel table (ChannelEntry::granted_total)

This trait abstracts the mechanism while ChannelRegistry remains the source of truth for stream lifecycle (routing, ordering, existence).

r[impl flow.channel.credit-based] r[impl flow.channel.all-transports]

Required Methods§

Source

fn on_data_received(&mut self, channel_id: ChannelId, bytes: u32)

Called when we receive data on a channel (receiver side).

The implementation may grant credit back to the sender:

  • Stream: queue a Message::Credit to send
  • SHM: increment ChannelEntry::granted_total atomically

r[impl flow.channel.credit-grant]

Source

fn wait_for_send_credit( &mut self, channel_id: ChannelId, bytes: u32, ) -> impl Future<Output = Result<()>> + Send

Wait until we have enough credit to send bytes on a channel (sender side).

  • Stream: check ChannelRegistry::outgoing_credit, wait on notify if insufficient
  • SHM: poll/futex wait on granted_total - sent_total >= bytes

Returns Ok(()) when credit is available, Err if the channel is closed/invalid.

r[impl flow.channel.zero-credit]

Source

fn consume_send_credit(&mut self, channel_id: ChannelId, bytes: u32)

Consume credit after sending data (sender side).

Called after successfully sending bytes on a channel.

  • Stream: decrement ChannelRegistry::outgoing_credit
  • SHM: increment local sent_total

r[impl flow.channel.credit-consume]

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§