|
| DispatcherSession (boost::asio::io_context &io_context, boost::asio::ip::tcp::socket &&socket) |
| Constructor for DispatcherSession.
|
|
| ~DispatcherSession () |
| Destructor for DispatcherSession. Cleans up the session and packet dispatcher.
|
|
template<IsPacket T>
requires std::is_base_of_v<Packet, T> |
bool | send_packet (const T &packet_arg) |
| Sends any packet derived from DerivedPacket through the network.
|
|
std::unique_ptr< Packet > | pop_packet_now () |
| Returns the earliest acquired packet. If packet queue is empty, returns nullptr.
|
|
boost::asio::awaitable< std::unique_ptr< Packet > > | pop_packet_async () |
|
bool | has_packets () |
| Checks if there are packets in the queue.
|
|
bool | secured () const noexcept |
| Checks if the session is secured using encryption.
|
|
constexpr bool | is_closed () const noexcept |
| Checks if the session is closed.
|
|
constexpr bool | alive () const noexcept |
| Checks if the session is alive.
|
|
void | setup_encryption (std::shared_ptr< mal_packet_weaver::crypto::EncryptionInterface > encryption) |
| Sets up encryption for the session using provided encryption interface.
|
|
void | set_packet_receiver (PacketReceiverFn const receiver) |
| Sets the packet receiver for the session.
|
|
void | enqueue_packet (PacketDispatcher::BasePacketPtr &&packet) |
| Enqueues a packet for processing.
|
|
template<IsPacket DerivedPacket> |
boost::asio::awaitable< std::unique_ptr< DerivedPacket > > | await_packet (float timeout=-1.0f) |
| Wait until the packet is registered in the dispatch system and return as soon as possible.
|
|
template<IsPacket DerivedPacket> |
boost::asio::awaitable< std::unique_ptr< DerivedPacket > > | await_packet (PacketFilterFunc< DerivedPacket > filter, float timeout=-1.0f) |
| Wait until a packet satisfying the filter condition is registered in the dispatch system and return as soon as possible.
|
|
template<IsPacket DerivedPacket> |
void | register_default_handler (PacketHandlerFunc< DerivedPacket > handler, PacketFilterFunc< DerivedPacket > filter={}, float delay=0.0f) |
| Registers a default handler for the provided packet type.
|
|
template<typename Arg1 , IsPacket CustomPacket> |
void | register_default_handler (PacketHandlerFunc< CustomPacket, Arg1 > &&handler, PacketFilterFunc< CustomPacket, Arg1 > &&filter={}, float delay=0.0f) |
| Register a default handler for the provided packet type.
|
|
template<typename Arg1 , typename Arg2 , typename... Args, IsPacket CustomPacket> |
void | register_default_handler (PacketHandlerFunc< CustomPacket, Arg1, Arg2, Args... > &&handler, PacketFilterFunc< CustomPacket, Arg1, Arg2, Args... > &&filter={}, float delay=0.0f) |
| Register a default handler for the provided packet type.
|
|
template<IsPacket CustomPacket, typename... FnArgs> |
void | register_default_handler (std::function< void(FnArgs...)> &&handler, std::function< bool(FnArgs...)> &&filter={}, float delay=0.0f) |
|
void | enqueue_promise (UniquePacketID packet_id, PacketDispatcher::shared_packet_promise promise) |
| Enqueues a promise associated with a packet.
|
|
void | enqueue_filter_promise (UniquePacketID packet_id, PacketDispatcher::promise_filter filtered_promise) |
| Enqueues a promise with a filter associated with a packet.
|
|
Session & | session () |
| Get a reference to the underlying session.
|
|
PacketDispatcher & | dispatcher () |
| Get a reference to the underlying packet dispatcher.
|
|
void | Destroy () |
|
Represents a session with packet dispatching functionality.
Definition at line 10 of file dispatcher-session.hpp.
template<IsPacket DerivedPacket>
Wait until a packet satisfying the filter condition is registered in the dispatch system and return as soon as possible.
This function template waits for a packet of a specific type, satisfying a provided filter condition, to be registered in the dispatch system. It can optionally wait for a specified timeout duration.
- Template Parameters
-
- Parameters
-
filter | A function to filter the packet. If the functor returns true, the packet will fulfill the promise. |
timeout | If less than or equal to zero, the function will not return until the promise is fulfilled. Otherwise, it will wait for the given timeout (in seconds) before returning. |
- Returns
- boost::asio::awaitable<std::unique_ptr<DerivedPacket>> A unique pointer to the received packet, or nullptr if the timeout was reached or the filter condition was not satisfied.
Definition at line 188 of file dispatcher-session.hpp.
template<typename Arg1 , IsPacket CustomPacket>
void mal_packet_weaver::DispatcherSession::register_default_handler |
( |
PacketHandlerFunc< CustomPacket, Arg1 > && | handler, |
|
|
PacketFilterFunc< CustomPacket, Arg1 > && | filter = {}, |
|
|
float | delay = 0.0f ) |
|
inline |
Register a default handler for the provided packet type.
This function registers a default packet handler for a specific packet type. The handler function can be provided, and if it returns false, the packet is passed to the next handler. An optional filter function can also be provided to determine whether the handler should be applied based on the packet's properties. A delay parameter can be used to postpone the handler's execution for a certain amount of time.
- Template Parameters
-
Arg1 | The type of argument 1 for the handler. |
Args | Additional argument types for the handler. |
CustomPacket | The type of packet for which the handler should be registered. |
- Parameters
-
handler | The packet handler function. |
filter | The packet filter function to determine whether the handler should be applied. |
delay | The delay in seconds before the handler is executed. (Default is 0.0) |
- Note
- Supported types for Args are: Session&, std::shared_ptr<Session>, io_context &, std::shared_ptr<PacketDispatcher>, and PacketDispatcher&. The std::unique_ptr<CustomPacket> type should be last.
Definition at line 239 of file dispatcher-session.hpp.
template<typename Arg1 , typename Arg2 , typename... Args, IsPacket CustomPacket>
void mal_packet_weaver::DispatcherSession::register_default_handler |
( |
PacketHandlerFunc< CustomPacket, Arg1, Arg2, Args... > && | handler, |
|
|
PacketFilterFunc< CustomPacket, Arg1, Arg2, Args... > && | filter = {}, |
|
|
float | delay = 0.0f ) |
|
inline |
Register a default handler for the provided packet type.
This function registers a default packet handler for a specific packet type. The handler function can be provided, and if it returns false, the packet is passed to the next handler. An optional filter function can also be provided to determine whether the handler should be applied based on the packet's properties. A delay parameter can be used to postpone the handler's execution for a certain amount of time.
- Template Parameters
-
Arg1 | The type of argument 1 for the handler. |
Arg2 | The type of argument 2 for the handler. |
Args | Additional argument types for the handler. |
CustomPacket | The type of packet for which the handler should be registered. |
- Parameters
-
handler | The packet handler function. |
filter | The packet filter function to determine whether the handler should be applied. |
delay | The delay in seconds before the handler is executed. (Default is 0.0) |
- Note
- Supported types for Args are: Session&, std::shared_ptr<Session>, io_context &, std::shared_ptr<PacketDispatcher>, and PacketDispatcher&. The std::unique_ptr<CustomPacket> type should be last.
Definition at line 331 of file dispatcher-session.hpp.
template<IsPacket DerivedPacket>
Registers a default handler for the provided packet type.
This function registers a default packet handler for a specific packet type. The handler function can be provided, and if it returns false, the packet is passed to the next handler. An optional filter function can also be provided to determine whether the handler should be applied based on the packet's properties. A delay parameter can be used to postpone the handler's execution for a certain amount of time.
- Todo
- Add an ability to delete handlers
- Template Parameters
-
DerivedPacket | The type of packet for which the handler should be registered. |
- Parameters
-
handler | The packet handler function. If it returns false, the packet will be passed to the next handler. |
filter | The packet filter function to determine whether the handler should be applied. (Optional) |
delay | The delay in seconds before the handler is executed. (Default is 0.0) |
Definition at line 213 of file dispatcher-session.hpp.