Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
session_info.h
Go to the documentation of this file.
1/*****************************************************************************
2BSD 3-Clause License
3
4Copyright (c) 2025, kcenon
5All rights reserved.
6*****************************************************************************/
7
8#pragma once
9
11
12#include <chrono>
13#include <memory>
14
15namespace kcenon::network::core {
16
27template <typename SessionType, bool HasActivityTracking>
29
35template <typename SessionType>
36struct session_info_base<SessionType, true> {
37 std::shared_ptr<SessionType> session;
38 std::chrono::steady_clock::time_point created_at;
39 std::chrono::steady_clock::time_point last_activity;
40
41 explicit session_info_base(std::shared_ptr<SessionType> sess)
42 : session(std::move(sess))
43 , created_at(std::chrono::steady_clock::now())
44 , last_activity(created_at) {}
45
49 void update_activity() { last_activity = std::chrono::steady_clock::now(); }
50
55 [[nodiscard]] auto idle_duration() const -> std::chrono::milliseconds {
56 return std::chrono::duration_cast<std::chrono::milliseconds>(
57 std::chrono::steady_clock::now() - last_activity);
58 }
59};
60
66template <typename SessionType>
67struct session_info_base<SessionType, false> {
68 std::shared_ptr<SessionType> session;
69
70 explicit session_info_base(std::shared_ptr<SessionType> sess)
71 : session(std::move(sess)) {}
72};
73
80template <typename SessionType>
82 session_info_base<SessionType,
84
85} // namespace kcenon::network::core
std::chrono::steady_clock::time_point last_activity
void update_activity()
Updates the last activity timestamp to current time.
session_info_base(std::shared_ptr< SessionType > sess)
auto idle_duration() const -> std::chrono::milliseconds
Calculates the idle duration since last activity.
Wrapper for session with optional activity tracking.
Customization point for session manager behavior.