pub struct ListenGroup<LI, CH, CAD>{ /* 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>
impl<LI, CH, CAD> ListenGroup<LI, CH, CAD>
Sourcepub fn new(
handler: impl GroupHandler<ListenIdent = LI, ConnHandler = CH, ConnAppData = CAD> + Send + Sync + 'static,
) -> Self
pub fn new( handler: impl GroupHandler<ListenIdent = LI, ConnHandler = CH, ConnAppData = CAD> + Send + Sync + 'static, ) -> Self
Create a new listener group.
Sourcepub fn with_idbag(
handler: impl GroupHandler<ListenIdent = LI, ConnHandler = CH, ConnAppData = CAD> + Send + Sync + 'static,
idbag: Arc<IdBagUsize>,
) -> Self
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.
Sourcepub fn add_listener(&self, spec: ListenerSpec<LI>)
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()
Sourcepub fn have_listener(&mut self, id: &LI) -> bool
pub fn have_listener(&mut self, id: &LI) -> bool
Check if there’s a listener with the identifier LI
.
Sourcepub async fn kill_listener(&self, lid: LI)
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.
Sourcepub async fn kill_connection(&self, cid: ArcIdUsize)
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.
Sourcepub async fn shutdown(&self)
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.
Sourcepub fn current_state(&self) -> Vec<LInfo<LI, CAD>>
pub fn current_state(&self) -> Vec<LInfo<LI, CAD>>
Get a snap-shot of the current listener group state.
Sourcepub fn with_cad<F, R>(&self, conn_id: usize, f: F) -> Option<R>
pub fn with_cad<F, R>(&self, conn_id: usize, f: F) -> Option<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.