Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
session_timeout.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6#include <chrono>
7#include <atomic>
8
9namespace kcenon::network {
10
12public:
13 explicit session_timeout_manager(std::chrono::seconds timeout = std::chrono::seconds(300))
14 : timeout_(timeout) {}
15
17 last_activity_ = std::chrono::steady_clock::now();
18 }
19
20 bool is_timed_out() const {
21 auto now = std::chrono::steady_clock::now();
22 auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(
23 now - last_activity_.load());
24 return elapsed > timeout_;
25 }
26
27 auto get_idle_time() const {
28 auto now = std::chrono::steady_clock::now();
29 return std::chrono::duration_cast<std::chrono::seconds>(
30 now - last_activity_.load());
31 }
32
33private:
34 std::chrono::seconds timeout_;
35 std::atomic<std::chrono::steady_clock::time_point> last_activity_{
36 std::chrono::steady_clock::now()};
37};
38
39} // namespace
session_timeout_manager(std::chrono::seconds timeout=std::chrono::seconds(300))
std::atomic< std::chrono::steady_clock::time_point > last_activity_
Main namespace for all Network System components.