ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
connection_attempt.h
Go to the documentation of this file.
1
25#pragma once
26
27#include <ascii-chat/common.h>
31#include <stdint.h>
32#include <stdbool.h>
33#include <time.h>
34
35/* ============================================================================
36 * Forward Declarations
37 * ============================================================================ */
38
39/* ============================================================================
40 * Connection State Enumeration
41 * ============================================================================ */
42
60
61/* ============================================================================
62 * Timeout Constants (in nanoseconds)
63 * ============================================================================ */
64
65#define CONN_TIMEOUT_TCP (3LL * NS_PER_SEC_INT)
66
67/* ============================================================================
68 * Connection Attempt Context
69 * ============================================================================ */
70
82typedef struct {
83 // State Machine
86
87 // Timeout Tracking (in nanoseconds)
90
91 // Transport ownership
93
94 // Statistics
97
98 // Reconnection Strategy
100
102
103/* ============================================================================
104 * Function Declarations
105 * ============================================================================ */
106
116
128
138
146
156
179 uint16_t server_port);
180
Platform abstraction layer umbrella header providing unified cross-platform API.
⚙️ Common definitions, error codes, macros, and types shared throughout the application
asciichat_error_t connection_attempt_tcp(connection_attempt_context_t *ctx, const char *server_address, uint16_t server_port)
Attempt TCP connection.
asciichat_error_t connection_context_init(connection_attempt_context_t *ctx)
Initialize connection attempt context.
connection_state_t
Simple TCP connection state machine.
@ CONN_STATE_CONNECTED
Successfully connected.
@ CONN_STATE_IDLE
Not connected, no attempt in progress.
@ CONN_STATE_DISCONNECTED
Clean disconnect (user initiated)
@ CONN_STATE_FAILED
Connection attempt failed.
@ CONN_STATE_ATTEMPTING
Attempting connection.
asciichat_error_t connection_attempt_websocket(connection_attempt_context_t *ctx, const char *ws_url)
Attempt WebSocket connection.
void connection_context_cleanup(connection_attempt_context_t *ctx)
Cleanup connection attempt context.
bool connection_check_timeout(const connection_attempt_context_t *ctx)
Check if connection attempt has exceeded timeout.
asciichat_error_t connection_state_transition(connection_attempt_context_t *ctx, connection_state_t new_state)
Transition to next connection state.
const char * connection_state_name(connection_state_t state)
Get human-readable state name for logging.
Shared connection ownership handle for TCP and WebSocket clients.
unsigned short uint16_t
Definition common.h:57
unsigned int uint32_t
Definition common.h:58
unsigned long long uint64_t
Definition common.h:59
asciichat_error_t
Error and exit codes - unified status values (0-255)
Definition error_codes.h:49
connection_state_t
ClangTool/LibTooling compatibility shim for stdbool.h.
Context for connection attempts (TCP or WebSocket)
connection_state_t current_state
Current connection state.
connection_state_t previous_state
Previous state (for debugging)
uint32_t reconnect_attempt
Reconnection attempt number (1st, 2nd, etc.)
bool is_reconnection
True if reconnecting after successful connection (not first connect)
uint64_t timeout_ns
Timeout for connection attempt.
uint32_t total_transitions
Total state transitions (for metrics)
uint64_t attempt_start_time_ns
When current attempt began.
connection_handle_t connection
Shared transport/client ownership handle.
⏱️ High-precision timing utilities using sokol_time.h and uthash
Transport abstraction layer for ACIP protocol.