ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
acds_handlers.c File Reference

ACIP Discovery Server (ACDS) packet handlers with O(1) dispatch. More...

Go to the source code of this file.

Data Structures

struct  acds_hash_entry_t
 Hash table entry for ACDS packet type to handler mapping. More...
 

Macros

#define ACDS_HASH_SIZE   32
 
#define ACDS_HANDLER_COUNT   11
 
#define ACDS_HASH(type)   ((type) % ACDS_HASH_SIZE)
 

Typedefs

typedef asciichat_error_t(* acip_acds_handler_func_t) (const void *payload, size_t payload_len, int client_socket, const char *client_ip, const acip_acds_callbacks_t *callbacks)
 

Functions

asciichat_error_t acip_handle_acds_packet (acip_transport_t *transport, packet_type_t type, const void *payload, size_t payload_len, int client_socket, const char *client_ip, const acip_acds_callbacks_t *callbacks)
 

Detailed Description

ACIP Discovery Server (ACDS) packet handlers with O(1) dispatch.

Implements O(1) array-based packet dispatching for ascii-chat Discovery Server. Handles ACIP packets 100-150: session management, WebRTC signaling, discovery.

Author
Zachary Fogg me@zf.nosp@m.o.gg
Date
January 2026

Definition in file acds_handlers.c.

Macro Definition Documentation

◆ ACDS_HANDLER_COUNT

#define ACDS_HANDLER_COUNT   11

Definition at line 31 of file acds_handlers.c.

◆ ACDS_HASH

#define ACDS_HASH (   type)    ((type) % ACDS_HASH_SIZE)

Definition at line 41 of file acds_handlers.c.

◆ ACDS_HASH_SIZE

#define ACDS_HASH_SIZE   32

Definition at line 30 of file acds_handlers.c.

Typedef Documentation

◆ acip_acds_handler_func_t

typedef asciichat_error_t(* acip_acds_handler_func_t) (const void *payload, size_t payload_len, int client_socket, const char *client_ip, const acip_acds_callbacks_t *callbacks)

Definition at line 26 of file acds_handlers.c.

Function Documentation

◆ acip_handle_acds_packet()

asciichat_error_t acip_handle_acds_packet ( acip_transport_t *  transport,
packet_type_t  type,
const void *  payload,
size_t  payload_len,
int  client_socket,
const char *  client_ip,
const acip_acds_callbacks_t *  callbacks 
)

Definition at line 118 of file acds_handlers.c.

120 {
121 if (!callbacks) {
122 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid callbacks");
123 }
124 (void)transport;
125
126 // O(1) dispatch via hash table lookup
127 int idx = acds_handler_hash_lookup(g_acds_handler_hash, type);
128 if (idx < 0) {
129 return SET_ERRNO(ERROR_INVALID_PARAM, "Unhandled ACDS packet type: %d from %s", type, client_ip);
130 }
131
132 return g_acds_handlers[idx](payload, payload_len, client_socket, client_ip, callbacks);
133}

Referenced by acds_client_handler().