Skip to main content

HandleStore

Struct HandleStore 

Source
pub struct HandleStore { /* private fields */ }
Expand description

Per-endpoint handle registry. Owns all body readers, writers, trailers, sessions, request-head rendezvous channels, and fetch-cancel tokens for a single IrohEndpoint.

When the endpoint is dropped, this store is dropped with it — all slot-maps are freed and any remaining handles become invalid.

Implementations§

Source§

impl HandleStore

Source

pub fn new(config: StoreConfig) -> Self

Create a new handle store with the given configuration.

Source

pub fn drain_timeout(&self) -> Duration

The configured drain timeout.

Source

pub fn max_chunk_size(&self) -> usize

The configured maximum chunk size.

Source

pub fn count_handles(&self) -> (usize, usize, usize, usize)

Snapshot of handle counts for observability.

Returns (active_readers, active_writers, active_sessions, total_handles).

Source

pub fn make_body_channel(&self) -> (BodyWriter, BodyReader)

Create a matched (writer, reader) pair using this store’s config.

Source

pub fn insert_reader(&self, reader: BodyReader) -> Result<u64, CoreError>

Insert a BodyReader and return a handle.

Source

pub fn insert_writer(&self, writer: BodyWriter) -> Result<u64, CoreError>

Insert a BodyWriter and return a handle.

Source

pub fn alloc_body_writer(&self) -> Result<(u64, BodyReader), CoreError>

Allocate a (writer_handle, reader) pair for streaming request bodies.

The writer handle is returned to JS. The reader must be stashed via store_pending_reader so the fetch path can claim it.

Source

pub fn store_pending_reader(&self, writer_handle: u64, reader: BodyReader)

Store the reader side of a newly allocated writer channel so that the fetch path can claim it with claim_pending_reader.

Source

pub fn claim_pending_reader(&self, writer_handle: u64) -> Option<BodyReader>

Claim the reader that was paired with writer_handle. Returns None if already claimed or never stored.

Source

pub async fn next_chunk(&self, handle: u64) -> Result<Option<Bytes>, CoreError>

Pull the next chunk from a reader handle.

Returns Ok(None) at EOF. After returning None the handle is cleaned up from the registry automatically.

Source

pub async fn send_chunk( &self, handle: u64, chunk: Bytes, ) -> Result<(), CoreError>

Push a chunk into a writer handle.

Chunks larger than the configured max_chunk_size are split automatically so individual messages stay within the backpressure budget.

Source

pub fn finish_body(&self, handle: u64) -> Result<(), CoreError>

Signal end-of-body by dropping the writer from the registry.

Source

pub fn cancel_reader(&self, handle: u64)

Drop a body reader, signalling cancellation of any in-flight read.

Source

pub fn insert_trailer_sender( &self, tx: Sender<Vec<(String, String)>>, ) -> Result<u64, CoreError>

Insert a trailer oneshot sender and return a handle.

Source

pub fn insert_trailer_receiver( &self, rx: Receiver<Vec<(String, String)>>, ) -> Result<u64, CoreError>

Insert a trailer oneshot receiver and return a handle.

Source

pub fn remove_trailer_sender(&self, handle: u64)

Remove (drop) a trailer sender without sending.

Source

pub fn alloc_trailer_sender(&self) -> Result<u64, CoreError>

Allocate a (tx, rx) trailer oneshot pair for sending request trailers from JavaScript to the Rust body encoder.

Returns the sender handle — JS holds this and calls send_trailers when it is done writing the request body. The matching rx is stored in pending_trailer_rxs and claimed by fetch() via claim_pending_trailer_rx.

Source

pub fn claim_pending_trailer_rx( &self, sender_handle: u64, ) -> Option<Receiver<Vec<(String, String)>>>

Claim the trailer receiver that was paired with the given sender handle.

Returns None if the handle was never allocated via alloc_trailer_sender or has already been claimed.

Source

pub fn send_trailers( &self, handle: u64, trailers: Vec<(String, String)>, ) -> Result<(), CoreError>

Deliver trailers from the JS side to the waiting Rust pump task.

Source

pub async fn next_trailer( &self, handle: u64, ) -> Result<Option<Vec<(String, String)>>, CoreError>

Await and retrieve trailers produced by the Rust pump task.

Source

pub fn insert_session(&self, entry: SessionEntry) -> Result<u64, CoreError>

Insert a SessionEntry and return a handle.

Source

pub fn lookup_session(&self, handle: u64) -> Option<Arc<SessionEntry>>

Look up a session by handle without consuming it.

Source

pub fn remove_session(&self, handle: u64) -> Option<Arc<SessionEntry>>

Remove a session entry by handle and return it.

Source

pub fn allocate_req_handle( &self, sender: Sender<ResponseHeadEntry>, ) -> Result<u64, CoreError>

Insert a response-head oneshot sender and return a handle.

Source

pub fn take_req_sender(&self, handle: u64) -> Option<Sender<ResponseHeadEntry>>

Remove and return the response-head sender for the given handle.

Source

pub fn alloc_fetch_token(&self) -> Result<u64, CoreError>

Allocate a cancellation token for an upcoming fetch call.

Source

pub fn cancel_in_flight(&self, token: u64)

Signal an in-flight fetch to abort.

Source

pub fn get_fetch_cancel_notify(&self, token: u64) -> Option<Arc<Notify>>

Retrieve the Notify for a fetch token (clones the Arc for use in select!).

Source

pub fn remove_fetch_token(&self, token: u64)

Remove a fetch cancel token after the fetch completes.

Source

pub fn sweep(&self, ttl: Duration)

Sweep all registries, removing entries older than ttl. Also compacts any registry that is empty after sweeping to reclaim the backing memory from traffic bursts.

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<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> CompatExt for T

Source§

fn compat(self) -> Compat<T>

Applies the Compat adapter by value. Read more
Source§

fn compat_ref(&self) -> Compat<&T>

Applies the Compat adapter by shared reference. Read more
Source§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the Compat adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more