104 struct sockaddr_storage addr;
119typedef void *(*tcp_client_handler_fn)(
void *arg);
338 void *thread_arg,
int stop_id,
const char *thread_name);
🔌 Cross-platform abstraction layer umbrella header for ascii-chat
asciichat_error_t
Error and exit codes - unified status values (0-255)
void(* tcp_client_foreach_fn)(socket_t socket, void *client_data, void *user_arg)
Callback for iterating over clients.
void tcp_server_set_cleanup_callback(tcp_server_t *server, tcp_client_cleanup_fn cleanup_fn)
Set client cleanup callback.
void tcp_server_reject_client(socket_t socket, const char *reason)
Reject client connection with reason.
void *(* tcp_client_handler_fn)(void *arg)
Client handler thread function type.
void(* tcp_client_cleanup_fn)(void *client_data)
Callback for client cleanup.
asciichat_error_t tcp_server_spawn_thread(tcp_server_t *server, socket_t client_socket, void *(*thread_func)(void *), void *thread_arg, int stop_id, const char *thread_name)
Spawn a worker thread for a client.
asciichat_error_t tcp_server_remove_client(tcp_server_t *server, socket_t socket)
Remove client from registry.
void tcp_server_foreach_client(tcp_server_t *server, tcp_client_foreach_fn callback, void *user_arg)
Iterate over all clients.
asciichat_error_t tcp_server_stop_client_threads(tcp_server_t *server, socket_t client_socket)
Stop all threads for a client in stop_id order.
asciichat_error_t tcp_server_init(tcp_server_t *server, const tcp_server_config_t *config)
Initialize TCP server.
asciichat_error_t tcp_server_get_client(tcp_server_t *server, socket_t socket, void **out_data)
Get client data.
int tcp_client_context_get_port(const tcp_client_context_t *ctx)
Get port number from client context.
asciichat_error_t tcp_server_run(tcp_server_t *server)
Run TCP server accept loop.
asciichat_error_t tcp_server_get_thread_count(tcp_server_t *server, socket_t client_socket, size_t *count)
Get thread count for a client.
void tcp_server_shutdown(tcp_server_t *server)
Shutdown TCP server.
const char * tcp_client_context_get_ip(const tcp_client_context_t *ctx, char *buf, size_t len)
Get formatted IP address from client context.
size_t tcp_server_get_client_count(tcp_server_t *server)
Get client count.
asciichat_error_t tcp_server_add_client(tcp_server_t *server, socket_t socket, void *client_data)
Add client to registry.
Cross-platform socket interface for ascii-chat.
Per-client connection context.
socket_t client_socket
Client connection socket.
socklen_t addr_len
Address length.
void * user_data
User-provided data from config.
void * client_data
User-provided client data.
UT_hash_handle hh
uthash handle
thread_pool_t * threads
Thread pool for client worker threads.
socket_t socket
Client socket (hash key)
TCP server configuration.
bool bind_ipv6
Whether to bind IPv6 socket.
void * user_data
User data passed to each client handler.
tcp_client_handler_fn client_handler
Client handler callback.
bool bind_ipv4
Whether to bind IPv4 socket.
const char * ipv4_address
IPv4 bind address (NULL or empty = don't bind)
int accept_timeout_sec
select() timeout in seconds (for responsive shutdown)
const char * ipv6_address
IPv6 bind address (NULL or empty = don't bind)
mutex_t clients_mutex
Mutex protecting client registry.
atomic_bool running
Server running flag (set false to shutdown)
tcp_server_config_t config
Server configuration.
tcp_client_entry_t * clients
Hash table of connected clients.
socket_t listen_socket
IPv4 listen socket.
socket_t listen_socket6
IPv6 listen socket.
tcp_client_cleanup_fn cleanup_fn
Callback for cleaning up client data.
🧵 Generic thread pool abstraction for managing worker threads
#️⃣ Wrapper for uthash.h that ensures common.h is included first