7 releases
new 0.1.1 | May 11, 2025 |
---|---|
0.1.0 | May 6, 2025 |
0.0.5 | Oct 2, 2024 |
0.0.4 | Sep 20, 2024 |
0.0.2 | Aug 20, 2024 |
#1660 in Network programming
133 downloads per month
28KB
508 lines
lstngrp
ListenGroup
is meant to collect a group of network listeners into a single
entity, and help track connections made against those listeners.
lib.rs
:
A ListenGroup
collects a set of network listeners, and the connections
they spawn, into a single abstraction, allowing them to easily share common
logic and data.
Overview
The ListenGroup
is the central object in this crate. After
instantiation of a ListenGroup
the application can call
[ListenGroup::add_listener()
] to register new (network) listeners to it.
When one of the listeners has received a connection, it calls the
connected()
trait method of a
GroupHandler
implementor (which was passed to the ListenGroup
on
its creation).
The GroupHandler::connected()
implementor must return, among other
things, an object that implements ConnHandler
, which will be called
(through its [ConnHandler::run()
] method), to handle the connection.
Per-listener context
The ListenGroup
uses a single GroupHandler
object for all listeners.
If the application needs per-listener-specific data, it can use an
associative container (like a HashMap
) in its GroupHandler
object to
map listeners' unique identifiers to listener-specific contexts in the
container. See the per_listener_ctx
example in lstngrp's repository for
an example implementation of this.
Dependencies
~11–21MB
~369K SLoC