|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
🌐 Client connection manager: TCP connection, reconnection with exponential backoff, and thread-safe transmission More...
Go to the source code of this file.
Macros | |
| #define | DEBUG_NETWORK 1 |
| #define | DEBUG_THREADS 1 |
| #define | DEBUG_MEMORY 1 |
| #define | MAX_RECONNECT_DELAY (5 * 1000 * 1000) |
Functions | |
| int | server_connection_init () |
| Initialize the server connection management subsystem. | |
| int | server_connection_establish (const char *address, int port, int reconnect_attempt, bool first_connection, bool has_ever_connected) |
| Establish connection to ascii-chat server. | |
| bool | server_connection_is_active () |
| Check if server connection is currently active. | |
| socket_t | server_connection_get_socket () |
| Get current socket file descriptor. | |
| acip_transport_t * | server_connection_get_transport (void) |
| Get ACIP transport instance. | |
| void | server_connection_set_transport (acip_transport_t *transport) |
| Set ACIP transport instance from connection fallback. | |
| uint32_t | server_connection_get_client_id () |
| Get client ID assigned by server. | |
| const char * | server_connection_get_ip () |
| Get resolved server IP address. | |
| void | server_connection_set_ip (const char *ip) |
| Set the server IP address. | |
| void | server_connection_close () |
| Close the server connection gracefully. | |
| void | server_connection_shutdown () |
| Emergency connection shutdown for signal handlers. | |
| void | server_connection_lost () |
| Signal that connection has been lost. | |
| bool | server_connection_is_lost () |
| Check if connection loss has been detected. | |
| void | server_connection_cleanup () |
| Cleanup connection management subsystem. | |
| asciichat_error_t | threaded_send_packet (packet_type_t type, const void *data, size_t len) |
| Thread-safe packet transmission. | |
| int | threaded_send_audio_batch_packet (const float *samples, int num_samples, int batch_count) |
| Thread-safe batched audio packet transmission. | |
| asciichat_error_t | threaded_send_audio_opus (const uint8_t *opus_data, size_t opus_size, int sample_rate, int frame_duration) |
| Thread-safe Opus audio frame transmission. | |
| asciichat_error_t | threaded_send_audio_opus_batch (const uint8_t *opus_data, size_t opus_size, const uint16_t *frame_sizes, int frame_count) |
| Thread-safe Opus audio batch packet transmission. | |
| int | threaded_send_ping_packet (void) |
| Thread-safe ping packet transmission. | |
| int | threaded_send_pong_packet (void) |
| Thread-safe pong packet transmission. | |
| int | threaded_send_stream_start_packet (uint32_t stream_type) |
| Thread-safe stream start packet transmission. | |
| int | threaded_send_terminal_size_with_auto_detect (unsigned short width, unsigned short height) |
| Thread-safe terminal size packet transmission with auto-detection. | |
| int | threaded_send_client_join_packet (const char *display_name, uint32_t capabilities) |
| Thread-safe client join packet transmission. | |
Variables | |
| crypto_handshake_context_t | g_crypto_ctx = {0} |
| Per-connection crypto handshake context. | |
🌐 Client connection manager: TCP connection, reconnection with exponential backoff, and thread-safe transmission
The connection management follows a robust state machine:
All packet transmission functions use a global send mutex to prevent interleaved packets on the wire. The socket file descriptor is protected with atomic operations for thread-safe access across multiple threads.
Implements exponential backoff with jitter:
Uses platform abstraction layer for:
Connection errors are classified into:
Definition in file src/client/server.c.
| #define DEBUG_MEMORY 1 |
Definition at line 96 of file src/client/server.c.
| #define DEBUG_NETWORK 1 |
Definition at line 94 of file src/client/server.c.
| #define DEBUG_THREADS 1 |
Definition at line 95 of file src/client/server.c.
| #define MAX_RECONNECT_DELAY (5 * 1000 * 1000) |
Maximum delay between reconnection attempts (microseconds)
Definition at line 215 of file src/client/server.c.