Struct ListenGroup

Source
pub struct ListenGroup<LI, CH, CAD>
where LI: Hash + Eq, CAD: Send,
{ /* private fields */ }
Expand description

Representation of a group of listeners.

Each listener will use the same connection handler.

Generics:

  • LI - Listener identifier. Used by the application to uniquely identify a specific listener.
  • CI - Connection information. Each connection is allicated a connection information context.

Implementations§

Source§

impl<LI, CH, CAD> ListenGroup<LI, CH, CAD>
where LI: Hash + Eq + Send + Sync + Clone + 'static, CH: ConnHandler + Send + Sync + 'static, CAD: Send + Sync + 'static,

Source

pub fn new( handler: impl GroupHandler<ListenIdent = LI, ConnHandler = CH, ConnAppData = CAD> + Send + Sync + 'static, ) -> Self

Create a new listener group.

Source

pub fn with_idbag( handler: impl GroupHandler<ListenIdent = LI, ConnHandler = CH, ConnAppData = CAD> + Send + Sync + 'static, idbag: Arc<IdBagUsize>, ) -> Self

Create a new listener group, using a supplied IdBag to generated unique identifiers.

Source

pub fn add_listener(&self, spec: ListenerSpec<LI>)

Register a new listener within this group.

This method will spawn a new tokio task, which means the caller must ensure that it is running within a runtime context. This happens automatically if the call is performed from an async function/method. For non-async contexts, threads can call Runtime::enter() or Handle::enter()

Source

pub fn have_listener(&mut self, id: &LI) -> bool

Check if there’s a listener with the identifier LI.

Source

pub async fn kill_listener(&self, lid: LI)

Kill the listener given a specific listener id.

If kill_conns is true, the killswitch of all of the listeners active connections will be triggered as well.

Source

pub async fn kill_connection(&self, cid: ArcIdUsize)

Terminate a connection given a connection identifier.

This function will not return until the background connection task has terminated.

Source

pub async fn shutdown(&self)

Shut down listener group.

This will first block any new listeners from being added to the group and block any running listeners from accepting new connections. Then it will shut down each listener, including all of its connections.

Source

pub fn current_state(&self) -> Vec<LInfo<LI, CAD>>

Get a snap-shot of the current listener group state.

Source

pub fn with_cad<F, R>(&self, conn_id: usize, f: F) -> Option<R>
where F: FnOnce(&CAD) -> R,

Run a closure, passing in a reference to a connection’s application-specific connection data to it.

Returns None if there’s no connection data associated with conn_id.

Closure should return quickly; it is called while an internal lock is being held.

Trait Implementations§

Source§

impl<LI, CH, CAD> Clone for ListenGroup<LI, CH, CAD>
where LI: Hash + Eq, CAD: Send,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<LI, CH, CAD> Freeze for ListenGroup<LI, CH, CAD>

§

impl<LI, CH, CAD> !RefUnwindSafe for ListenGroup<LI, CH, CAD>

§

impl<LI, CH, CAD> Send for ListenGroup<LI, CH, CAD>
where LI: Send, CAD: Sync,

§

impl<LI, CH, CAD> Sync for ListenGroup<LI, CH, CAD>
where LI: Send, CAD: Sync,

§

impl<LI, CH, CAD> Unpin for ListenGroup<LI, CH, CAD>

§

impl<LI, CH, CAD> !UnwindSafe for ListenGroup<LI, CH, CAD>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.