Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
ws_session_manager.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6
8
9namespace kcenon::network::core {
10
11// Forward declaration
12class ws_connection;
13
50class ws_session_manager : public session_manager_base<ws_connection> {
51public:
52 using ws_connection_ptr = std::shared_ptr<ws_connection>;
54
61 : base_type(config) {}
62
63 // =========================================================================
64 // Backward-compatible API (aliases to base class methods)
65 // =========================================================================
66
78 auto add_connection(ws_connection_ptr conn, const std::string& conn_id = "")
79 -> std::string {
80 return add_session_with_id(std::move(conn), conn_id);
81 }
82
91 auto remove_connection(const std::string& conn_id) -> bool {
92 return remove_session(conn_id);
93 }
94
103 [[nodiscard]] auto get_connection(const std::string& conn_id) const
105 return get_session(conn_id);
106 }
107
115 [[nodiscard]] auto get_all_connections() const -> std::vector<ws_connection_ptr> {
116 return get_all_sessions();
117 }
118
126 [[nodiscard]] auto get_all_connection_ids() const -> std::vector<std::string> {
127 return get_all_session_ids();
128 }
129
135 [[nodiscard]] auto get_connection_count() const -> size_t {
136 return get_session_count();
137 }
138
145
153 static auto generate_connection_id() -> std::string { return generate_id(); }
154};
155
156} // namespace kcenon::network::core
Thread-safe session lifecycle management template.
auto add_session_with_id(session_ptr session, const std::string &session_id="") -> std::string
auto get_session(const std::string &session_id) const -> session_ptr
auto get_all_session_ids() const -> std::vector< std::string >
auto remove_session(const std::string &session_id) -> bool
auto get_all_sessions() const -> std::vector< session_ptr >
Thread-safe WebSocket session lifecycle management.
auto get_all_connection_ids() const -> std::vector< std::string >
Gets all connection IDs.
ws_session_manager(const session_config &config=session_config())
Constructs a WebSocket session manager.
auto get_connection_count() const -> size_t
Gets the current connection count.
auto get_all_connections() const -> std::vector< ws_connection_ptr >
Gets all active connections.
auto get_connection(const std::string &conn_id) const -> ws_connection_ptr
Gets a connection by ID.
auto add_connection(ws_connection_ptr conn, const std::string &conn_id="") -> std::string
Adds a connection to the manager.
static auto generate_connection_id() -> std::string
Generates a unique connection ID.
auto clear_all_connections() -> void
Clears all connections.
std::shared_ptr< ws_connection > ws_connection_ptr
auto remove_connection(const std::string &conn_id) -> bool
Removes a connection from the manager.
tracing_config config
Definition exporters.cpp:29
Configuration for session management.