ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
include/ascii-chat/network/tcp/client.h
Go to the documentation of this file.
1
29#ifndef NETWORK_TCP_CLIENT_H
30#define NETWORK_TCP_CLIENT_H
31
32#include <ascii-chat/atomic.h>
33#include <stdbool.h>
34#include <stdint.h>
35
36#include "../../platform/socket.h"
37#include "../../network/packet/packet.h"
38
67typedef struct tcp_client {
68 /* ========================================================================
69 * Connection State (TCP-Specific)
70 * ======================================================================== */
71
74
77
80
83
86
88 char server_ip[256];
89
92
95
97
123
147void tcp_client_destroy(tcp_client_t **client_ptr);
148
149/* ============================================================================
150 * Connection State Queries
151 * ============================================================================ */
152
158bool tcp_client_is_active(const tcp_client_t *client);
159
165bool tcp_client_is_lost(const tcp_client_t *client);
166
173
180
181/* ============================================================================
182 * Connection Control
183 * ============================================================================ */
184
190
195void tcp_client_close(tcp_client_t *client);
196
202
203/* ============================================================================
204 * Connection Establishment
205 * ============================================================================ */
206
222int tcp_client_connect(tcp_client_t *client, const char *address, int port, int reconnect_attempt,
223 bool first_connection, bool has_ever_connected);
224
225/* ============================================================================
226 * Thread-Safe Packet Transmission
227 * ============================================================================ */
228
242int tcp_client_send_packet(tcp_client_t *client, packet_type_t type, const void *data, size_t len);
243
250
257
258#endif /* NETWORK_TCP_CLIENT_H */
⚛️ Atomic operations abstraction layer with debug tracking
void tcp_client_t
unsigned int uint32_t
Definition common.h:58
packet_type_t
Network protocol packet type enumeration.
Definition packet.h:286
int socket_t
tcp_client_t * tcp_client_create(void)
Create and initialize a TCP client instance.
socket_t tcp_client_get_socket(const tcp_client_t *client)
Get current socket descriptor.
bool tcp_client_is_active(const tcp_client_t *client)
Check if connection is currently active.
int tcp_client_send_pong(tcp_client_t *client)
Send pong packet.
int tcp_client_connect(tcp_client_t *client, const char *address, int port, int reconnect_attempt, bool first_connection, bool has_ever_connected)
Establish TCP connection to server.
void tcp_client_close(tcp_client_t *client)
Close connection gracefully.
int tcp_client_send_ping(tcp_client_t *client)
Send ping packet.
bool tcp_client_is_lost(const tcp_client_t *client)
Check if connection was lost.
void tcp_client_shutdown(tcp_client_t *client)
Shutdown connection forcefully (for signal handlers)
uint32_t tcp_client_get_id(const tcp_client_t *client)
Get client ID assigned by server.
struct tcp_client tcp_client_t
TCP client connection state (network-layer only)
void tcp_client_signal_lost(tcp_client_t *client)
Signal that connection was lost (triggers reconnection)
void tcp_client_destroy(tcp_client_t **client_ptr)
Destroy TCP client and free all resources.
int tcp_client_send_packet(tcp_client_t *client, packet_type_t type, const void *data, size_t len)
Send packet with thread-safe mutex protection.
ClangTool/LibTooling compatibility shim for stdbool.h.
Atomic value wrapper for integral/boolean types.
Definition atomic.h:76
Mutex type (POSIX: pthread_mutex_t with debug tracking)
TCP client connection state (network-layer only)