99static bool g_ping_thread_created =
false;
109static atomic_bool g_ping_thread_exited =
false;
116#define PING_INTERVAL_SECONDS 3
119#define PING_SLEEP_INTERVAL_SECONDS 1
150static void *ping_thread_func(
void *arg) {
158 static fps_t fps_tracker = {0};
159 static bool fps_tracker_initialized =
false;
160 if (!fps_tracker_initialized) {
162 fps_tracker_initialized =
true;
172 log_debug(
"Connection inactive, exiting ping thread");
178 log_debug(
"Rekey threshold reached, initiating session rekey");
195 struct timespec current_time;
196 (void)clock_gettime(CLOCK_MONOTONIC, ¤t_time);
197 fps_frame(&fps_tracker, ¤t_time,
"ping sent");
212 atomic_store(&g_ping_thread_exited,
true);
235 if (g_ping_thread_created) {
236 log_warn(
"Ping thread already created");
241 atomic_store(&g_ping_thread_exited,
false);
243 log_error(
"Failed to spawn ping thread in worker pool");
248 g_ping_thread_created =
true;
261 if (!g_ping_thread_created) {
270 while (wait_count < 20 && !atomic_load(&g_ping_thread_exited)) {
275 if (!atomic_load(&g_ping_thread_exited)) {
276 log_warn(
"Ping thread not responding - will be joined by thread pool");
280 g_ping_thread_created =
false;
282 log_info(
"Ping thread stopped and joined");
293 return atomic_load(&g_ping_thread_exited);
🔌 Cross-platform abstraction layer umbrella header for ascii-chat
#define LOG_ERRNO_IF_SET(message)
Check if any error occurred and log it if so.
thread_pool_t * g_client_worker_pool
Global client worker thread pool.
bool should_exit()
Check if client should exit.
⏱️ FPS tracking utility for monitoring frame throughput across all threads
bool server_connection_is_active()
Check if server connection is currently active.
int threaded_send_ping_packet(void)
Thread-safe ping packet transmission.
bool server_connection_is_lost()
Check if connection loss has been detected.
void server_connection_lost()
Signal that connection has been lost.
bool crypto_client_should_rekey(void)
Check if session rekeying should be triggered.
int crypto_client_initiate_rekey(void)
Initiate session rekeying (client-initiated)
bool keepalive_thread_exited()
Check if keepalive thread has exited.
int keepalive_start_thread()
Start keepalive/ping thread.
void keepalive_stop_thread()
Stop keepalive/ping thread.
void fps_frame(fps_t *tracker, const struct timespec *current_time, const char *context)
Track a frame and detect lag conditions.
void fps_init_with_interval(fps_t *tracker, int expected_fps, const char *name, uint64_t report_interval_us)
Initialize FPS tracker with custom report interval.
void asciichat_errno_cleanup(void)
Cleanup error system resources.
#define log_warn(...)
Log a WARN message.
#define log_error(...)
Log an ERROR message.
#define log_info(...)
Log an INFO message.
#define log_debug(...)
Log a DEBUG message.
#define PING_SLEEP_INTERVAL_SECONDS
#define PING_INTERVAL_SECONDS
ascii-chat Client Connection Keepalive Management Interface
ascii-chat Server Mode Entry Point Header
ascii-chat Client Server Connection Management Interface
Server cryptographic operations and per-client handshake management.
asciichat_error_t thread_pool_spawn(thread_pool_t *pool, void *(*thread_func)(void *), void *thread_arg, int stop_id, const char *thread_name)
Spawn a worker thread in the pool.
🧵 Generic thread pool abstraction for managing worker threads