24#include <ascii-chat/common.h>
25#include <ascii-chat/network/acip/transport.h>
26#include <ascii-chat/platform/abstraction.h>
33struct websocket_client;
61#define CONN_TIMEOUT_TCP (3LL * NS_PER_SEC_INT)
172 uint16_t server_port,
struct tcp_client *pre_created_tcp_client);
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 via TCP.
@ 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 TCP 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.
asciichat_error_t connection_attempt_tcp(connection_attempt_context_t *ctx, const char *server_address, uint16_t server_port, struct tcp_client *pre_created_tcp_client)
Attempt TCP connection.
Context for TCP connection attempts.
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.)
struct tcp_client * tcp_client_instance
TCP client instance - owned by context.
acip_transport_t * active_transport
Currently active transport.
bool is_reconnection
True if reconnecting after successful connection (not first connect)
uint64_t timeout_ns
Timeout for connection attempt.
struct websocket_client * ws_client_instance
WebSocket client instance - owned by context.
uint32_t total_transitions
Total state transitions (for metrics)
uint64_t attempt_start_time_ns
When current attempt began.