ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
comprehensive.c File Reference

Comprehensive stubs for WASM build - network, encoding, analysis. More...

Go to the source code of this file.

Typedefs

typedef void h265_encoder_t
 
typedef void video_frame_t
 
typedef void acds_client_config_t
 
typedef void acds_client_t
 
typedef void audio_context_t
 
typedef void client_audio_pipeline_config_t
 
typedef void acip_client_callbacks_t
 
typedef void wav_writer_t
 
typedef void acds_session_lookup_result_t
 
typedef struct audio_ring_buffer audio_ring_buffer_t
 
typedef struct audio_pipeline audio_pipeline_t
 
typedef struct client_audio_pipeline client_audio_pipeline_t
 
typedef void tcp_client_t
 
typedef void webrtc_peer_manager_t
 

Functions

bool socket_is_valid (socket_t sock)
 Check if a socket handle is valid.
 
int socket_close (socket_t sock)
 Close a socket.
 
int socket_shutdown (socket_t sock, int how)
 Shutdown socket I/O.
 
ssize_t socket_send (socket_t sock, const void *buf, size_t len, int flags)
 Send data on a socket.
 
ssize_t socket_recv (socket_t sock, void *buf, size_t len, int flags)
 Receive data from a socket.
 
int socket_poll (struct pollfd *fds, nfds_t nfds, int64_t timeout_ns)
 Poll sockets for events (multiplexed I/O)
 
bool socket_is_would_block_error (int error_code)
 Check if error code indicates "would block" (non-blocking socket would wait)
 
bool socket_is_invalid_socket_error (int error_code)
 Check if error code indicates a closed/invalid socket.
 
const char * socket_get_error_string (void)
 Get last socket error as string.
 
int socket_get_last_error (void)
 Get last socket error code.
 
asciichat_error_t h265_encode (h265_encoder_t *encoder, uint16_t width, uint16_t height, const uint8_t *pixel_data, uint8_t *out_data, size_t *out_len)
 
void h265_encoder_destroy (h265_encoder_t *encoder)
 
asciichat_error_t h265_encoder_flush (h265_encoder_t *encoder, uint8_t *out_data, size_t *out_len)
 
void h265_encoder_request_keyframe (h265_encoder_t *encoder)
 
void audio_analysis_destroy (void)
 Cleanup audio analysis.
 
void audio_analysis_print_report (void)
 Print audio analysis report.
 
void audio_analysis_track_received_packet (uint32_t timestamp)
 
void audio_analysis_track_sent_packet (uint32_t timestamp)
 
void audio_analysis_track_sent_sample (float sample)
 Track sent audio sample.
 
void audio_analysis_track_received_sample (float sample)
 Track received audio sample.
 
size_t audio_ring_buffer_available_read (audio_ring_buffer_t *rb)
 Get number of samples available for reading.
 
void audio_set_pipeline (audio_context_t *ctx, void *pipeline)
 Set audio pipeline for echo cancellation.
 
asciichat_error_t audio_write_samples (void *ctx, const float *samples, int count)
 
asciichat_error_t audio_read_samples (void *ctx, float *buffer, int count)
 
client_audio_pipeline_t * client_audio_pipeline_create (const client_audio_pipeline_config_t *config)
 Create a new client audio pipeline.
 
void client_audio_pipeline_default_config (void)
 Get default configuration.
 
void client_audio_pipeline_destroy (client_audio_pipeline_t *pipeline)
 Destroy a client audio pipeline.
 
asciichat_error_t client_audio_pipeline_capture (client_audio_pipeline_t *pipeline, const float *samples, size_t count)
 
void client_audio_pipeline_playback (client_audio_pipeline_t *pipeline, const float *samples, size_t count)
 
asciichat_error_t acip_send_image_frame (acip_transport_t *transport, const void *pixel_data, uint32_t width, uint32_t height, uint32_t pixel_format)
 Send image frame to server (client → server)
 
asciichat_error_t acip_client_receive_and_dispatch (acip_transport_t *transport, const acip_client_callbacks_t *callbacks)
 Receive packet from server and dispatch to callbacks.
 
void acip_transport_destroy (acip_transport_t *transport)
 Destroy transport and free all resources.
 
acip_transport_t * acip_tcp_transport_create (const char *name, socket_t sockfd, crypto_context_t *crypto_ctx)
 Create TCP transport from existing socket.
 
asciichat_error_t connection_attempt_tcp (const char *address, int port)
 
bool wav_dump_enabled (void)
 Check if audio dumping is enabled via environment.
 
void * wav_writer_open (const char *path)
 
int wav_writer_write (wav_writer_t *writer, const float *samples, int num_samples)
 Write audio samples to WAV file.
 
void wav_writer_close (void *wav)
 
asciichat_error_t webrtc_peer_manager_handle_sdp (webrtc_peer_manager_t *mgr, const char *sdp)
 
int webrtc_peer_manager_handle_ice (webrtc_peer_manager_t *mgr, const char *candidate)
 
void lifecycle_destroy_commit (lifecycle_t *lc)
 
bool lifecycle_destroy_once (lifecycle_t *lc)
 
bool lifecycle_reset (lifecycle_t *lc)
 
void acds_client_config_init_defaults (acds_client_config_t *config)
 Initialize ACDS client configuration with defaults.
 
acds_client_t * acds_client_connect (const acds_client_config_t *config, void *ctx)
 
void acds_client_disconnect (acds_client_t *client)
 Disconnect from ACDS server.
 
asciichat_error_t acds_session_lookup (acds_client_t *client, const char *session_string, acds_session_lookup_result_t *result)
 Look up session by string.
 
asciichat_error_t parse_private_key (const char *key_data, size_t key_len)
 
bool validate_ssh_key_file (const char *path)
 Validate SSH key file before parsing.
 
asciichat_error_t discovery_keys_verify (const char *acds_server, const char *key_spec, uint8_t pubkey_out[32])
 Verify and load ACDS server public key.
 
void pubkey_to_hex (const uint8_t pubkey[32], char hex_out[65])
 Convert Ed25519 public key to hex string.
 
asciichat_error_t thread_pool_spawn (void *pool, void *(*thread_func)(void *), void *thread_arg, int stop_id, const char *name)
 Spawn a worker thread in the pool.
 
asciichat_error_t thread_pool_stop_all (void *pool)
 Stop all threads in the pool in stop_id order.
 
bool platform_is_interactive (void)
 Check if interactive prompting is available.
 

Detailed Description

Comprehensive stubs for WASM build - network, encoding, analysis.

Definition in file comprehensive.c.

Typedef Documentation

◆ acds_client_config_t

typedef void acds_client_config_t

Definition at line 23 of file comprehensive.c.

◆ acds_client_t

typedef void acds_client_t

Definition at line 24 of file comprehensive.c.

◆ acds_session_lookup_result_t

Definition at line 29 of file comprehensive.c.

◆ acip_client_callbacks_t

Definition at line 27 of file comprehensive.c.

◆ audio_context_t

typedef void audio_context_t

Definition at line 25 of file comprehensive.c.

◆ audio_pipeline_t

typedef struct audio_pipeline audio_pipeline_t

Definition at line 142 of file comprehensive.c.

◆ audio_ring_buffer_t

Definition at line 141 of file comprehensive.c.

◆ client_audio_pipeline_config_t

Definition at line 26 of file comprehensive.c.

◆ client_audio_pipeline_t

typedef struct client_audio_pipeline client_audio_pipeline_t

Definition at line 143 of file comprehensive.c.

◆ h265_encoder_t

typedef void h265_encoder_t

Definition at line 21 of file comprehensive.c.

◆ tcp_client_t

typedef void tcp_client_t

Definition at line 227 of file comprehensive.c.

◆ video_frame_t

typedef void video_frame_t

Definition at line 22 of file comprehensive.c.

◆ wav_writer_t

typedef void wav_writer_t

Definition at line 28 of file comprehensive.c.

◆ webrtc_peer_manager_t

typedef void webrtc_peer_manager_t

Definition at line 259 of file comprehensive.c.

Function Documentation

◆ acds_client_config_init_defaults()

void acds_client_config_init_defaults ( acds_client_config_t *  config)

Initialize ACDS client configuration with defaults.

Sets default values:

  • server_address: "127.0.0.1"
  • server_port: 27225
  • timeout_ms: 5000
Parameters
configConfiguration to initialize

Definition at line 291 of file comprehensive.c.

291 {
292 (void)config;
293}

◆ acds_client_connect()

acds_client_t * acds_client_connect ( const acds_client_config_t *  config,
void *  ctx 
)

Definition at line 295 of file comprehensive.c.

295 {
296 (void)config;
297 (void)ctx;
298 return NULL;
299}

◆ acds_client_disconnect()

void acds_client_disconnect ( acds_client_t *  client)

Disconnect from ACDS server.

Closes the connection and cleans up resources.

Parameters
clientClient handle

Definition at line 301 of file comprehensive.c.

301 {
302 (void)client;
303}

◆ acds_session_lookup()

asciichat_error_t acds_session_lookup ( acds_client_t *  client,
const char *  session_string,
acds_session_lookup_result_t *  result 
)

Look up session by string.

Sends SESSION_LOOKUP packet and receives SESSION_INFO response.

Parameters
clientConnected ACDS client
session_stringSession string to look up
resultLookup result (output)
Returns
ASCIICHAT_OK on success, error code on failure

Definition at line 305 of file comprehensive.c.

306 {
307 (void)client;
308 (void)session_string;
309 (void)result;
310 return SET_ERRNO(ERROR_NOT_SUPPORTED, "ACDS not supported in WASM");
311}
#define SET_ERRNO(code, context_msg,...)
Set error code with custom context message and log it, returning the error code.
@ ERROR_NOT_SUPPORTED
Definition error_codes.h:74

References ERROR_NOT_SUPPORTED, and SET_ERRNO.

◆ acip_client_receive_and_dispatch()

asciichat_error_t acip_client_receive_and_dispatch ( acip_transport_t *  transport,
const acip_client_callbacks_t *  callbacks 
)

Receive packet from server and dispatch to callbacks.

High-level receive function for client side. Receives a single packet from the transport, handles decryption, and dispatches to appropriate callback handler.

Parameters
transportTransport instance
callbacksCallback structure for handling received packets
Returns
ASCIICHAT_OK on success, error code on failure

Definition at line 207 of file comprehensive.c.

208 {
209 (void)transport;
210 (void)callbacks;
211 return SET_ERRNO(ERROR_NOT_SUPPORTED, "ACIP not supported in WASM");
212}

References ERROR_NOT_SUPPORTED, and SET_ERRNO.

◆ acip_send_image_frame()

asciichat_error_t acip_send_image_frame ( acip_transport_t *  transport,
const void *  pixel_data,
uint32_t  width,
uint32_t  height,
uint32_t  pixel_format 
)

Send image frame to server (client → server)

Sends webcam video frame as RGB24 pixel data.

Parameters
transportTransport instance
pixel_dataRGB24 pixel data (width * height * 3 bytes)
widthFrame width in pixels
heightFrame height in pixels
pixel_formatPixel format (e.g., RGB24)
Returns
ASCIICHAT_OK on success, error code on failure

Definition at line 197 of file comprehensive.c.

198 {
199 (void)transport;
200 (void)pixel_data;
201 (void)width;
202 (void)height;
203 (void)pixel_format;
204 return SET_ERRNO(ERROR_NOT_SUPPORTED, "ACIP not supported in WASM");
205}

References ERROR_NOT_SUPPORTED, and SET_ERRNO.

◆ acip_tcp_transport_create()

acip_transport_t * acip_tcp_transport_create ( const char *  name,
socket_t  sockfd,
crypto_context_t *  crypto_ctx 
)

Create TCP transport from existing socket.

Parameters
nameDebug name for tracking this transport (required, e.g., "transport_client_5")
sockfdConnected socket descriptor
crypto_ctxOptional crypto context (may be NULL)
Returns
Transport instance or NULL on error
Note
Caller retains socket ownership (transport doesn't close on destroy)

Definition at line 218 of file comprehensive.c.

218 {
219 (void)name;
220 (void)sockfd;
221 (void)crypto_ctx;
222 return NULL;
223}

◆ acip_transport_destroy()

void acip_transport_destroy ( acip_transport_t *  transport)

Destroy transport and free all resources.

Parameters
transportTransport to destroy (may be NULL)
Note
Calls close() first if still connected
Frees the transport structure itself
Safe to pass NULL

Definition at line 214 of file comprehensive.c.

214 {
215 (void)transport;
216}

◆ audio_analysis_destroy()

void audio_analysis_destroy ( void  )

Cleanup audio analysis.

Definition at line 119 of file comprehensive.c.

119{}

◆ audio_analysis_print_report()

void audio_analysis_print_report ( void  )

Print audio analysis report.

Definition at line 121 of file comprehensive.c.

121{}

◆ audio_analysis_track_received_packet()

void audio_analysis_track_received_packet ( uint32_t  timestamp)

Definition at line 123 of file comprehensive.c.

123 {
124 (void)timestamp;
125}

◆ audio_analysis_track_received_sample()

void audio_analysis_track_received_sample ( float  sample)

Track received audio sample.

Parameters
sampleAudio sample value

Definition at line 135 of file comprehensive.c.

135 {
136 (void)sample;
137}

◆ audio_analysis_track_sent_packet()

void audio_analysis_track_sent_packet ( uint32_t  timestamp)

Definition at line 127 of file comprehensive.c.

127 {
128 (void)timestamp;
129}

◆ audio_analysis_track_sent_sample()

void audio_analysis_track_sent_sample ( float  sample)

Track sent audio sample.

Parameters
sampleAudio sample value

Definition at line 131 of file comprehensive.c.

131 {
132 (void)sample;
133}

◆ audio_read_samples()

asciichat_error_t audio_read_samples ( void *  ctx,
float *  buffer,
int  count 
)

Definition at line 162 of file comprehensive.c.

162 {
163 (void)ctx;
164 (void)buffer;
165 (void)count;
166 return ASCIICHAT_OK;
167}
@ ASCIICHAT_OK
Definition error_codes.h:51

References ASCIICHAT_OK.

◆ audio_write_samples()

asciichat_error_t audio_write_samples ( void *  ctx,
const float *  samples,
int  count 
)

Definition at line 155 of file comprehensive.c.

155 {
156 (void)ctx;
157 (void)samples;
158 (void)count;
159 return ASCIICHAT_OK;
160}

References ASCIICHAT_OK.

◆ client_audio_pipeline_capture()

asciichat_error_t client_audio_pipeline_capture ( client_audio_pipeline_t *  pipeline,
const float *  samples,
size_t  count 
)

Definition at line 182 of file comprehensive.c.

182 {
183 (void)pipeline;
184 (void)samples;
185 (void)count;
186 return ASCIICHAT_OK;
187}

References ASCIICHAT_OK.

◆ client_audio_pipeline_create()

client_audio_pipeline_t * client_audio_pipeline_create ( const client_audio_pipeline_config_t *  config)

Create a new client audio pipeline.

Parameters
configPipeline configuration (NULL for defaults)
Returns
New pipeline instance, or NULL on failure

Allocates and initializes all audio processing components. Must be destroyed with client_audio_pipeline_destroy().

Create a new client audio pipeline.

This function:

  • Allocates the pipeline structure
  • Initializes Opus encoder/decoder
  • Sets up WebRTC AEC3 echo cancellation
  • Configures all audio processing parameters

Definition at line 171 of file comprehensive.c.

171 {
172 (void)config;
173 return NULL;
174}

◆ client_audio_pipeline_default_config()

void client_audio_pipeline_default_config ( void  )

Get default configuration.

Returns
Configuration with sensible defaults for voice chat

Definition at line 176 of file comprehensive.c.

176{}

◆ client_audio_pipeline_destroy()

void client_audio_pipeline_destroy ( client_audio_pipeline_t *  pipeline)

Destroy a client audio pipeline.

Parameters
pipelinePipeline to destroy (can be NULL)

Frees all resources including SpeexDSP states, Opus codec, and all work buffers.

Definition at line 178 of file comprehensive.c.

178 {
179 (void)pipeline;
180}

◆ client_audio_pipeline_playback()

void client_audio_pipeline_playback ( client_audio_pipeline_t *  pipeline,
const float *  samples,
size_t  count 
)

Definition at line 189 of file comprehensive.c.

189 {
190 (void)pipeline;
191 (void)samples;
192 (void)count;
193}

◆ connection_attempt_tcp()

asciichat_error_t connection_attempt_tcp ( const char *  address,
int  port 
)

Definition at line 229 of file comprehensive.c.

229 {
230 (void)address;
231 (void)port;
232 return SET_ERRNO(ERROR_NOT_SUPPORTED, "TCP not supported in WASM");
233}

References ERROR_NOT_SUPPORTED, and SET_ERRNO.

◆ discovery_keys_verify()

asciichat_error_t discovery_keys_verify ( const char *  acds_server,
const char *  key_spec,
uint8_t  pubkey_out[32] 
)

Verify and load ACDS server public key.

This function handles all ACDS key verification scenarios:

Automatic Trust (discovery-service.ascii-chat.com only):

  • If acds_server == "discovery-service.ascii-chat.com" and key_spec == NULL:
    • Downloads from ACDS_OFFICIAL_KEY_SSH_URL or ACDS_OFFICIAL_KEY_GPG_URL
    • Caches key locally
    • Trusts without user verification (first time)
    • Requires user verification if key changes

Explicit Key Specification:

  • HTTPS URL: Downloads key from URL, caches it
  • Local file: Loads key from file path
  • github:user: Fetches SSH or GPG key from GitHub
  • gitlab:user.gpg: Fetches GPG key from GitLab

Caching Behavior:

  • Keys are cached in ~/.config/ascii-chat/acds_keys/<hostname>/
  • Cache invalidation requires user confirmation (prevents MITM attacks)
Parameters
acds_serverACDS server hostname (e.g., "acds.example.com")
key_specKey specification:
  • NULL: automatic trust for discovery-service.ascii-chat.com only
  • HTTPS URL: https://example.com/key.pub
  • File path: /path/to/key.pub or ~/.ssh/server.pub
  • GitHub: github:username
  • GitLab: gitlab:username.gpg
pubkey_outEd25519 public key output (32 bytes)
Returns
ASCIICHAT_OK on success, error code otherwise

Definition at line 326 of file comprehensive.c.

326 {
327 (void)acds_server;
328 (void)key_spec;
329 (void)pubkey_out;
330 return SET_ERRNO(ERROR_CRYPTO_KEY, "discovery_keys_verify not supported in WASM");
331}
@ ERROR_CRYPTO_KEY
Definition error_codes.h:97

References ERROR_CRYPTO_KEY, and SET_ERRNO.

◆ h265_encode()

asciichat_error_t h265_encode ( h265_encoder_t *  encoder,
uint16_t  width,
uint16_t  height,
const uint8_t *  ascii_data,
uint8_t *  output_buf,
size_t *  output_size 
)

Encode an ASCII art frame

The encoder automatically detects size changes and reinitializes when needed. The output packet includes frame dimensions so decoder can reconfigure.

Parameters
encoderEncoder handle
widthCurrent frame width (characters)
heightCurrent frame height (characters)
ascii_dataRaw ASCII character grid (width × height bytes)
output_bufBuffer for encoded output
output_sizeInput: buffer size, Output: actual encoded size
Returns
Error code (ASCIICHAT_OK on success)

OUTPUT PACKET FORMAT: [flags: u8][width: u16][height: u16][x265_data...]

Definition at line 91 of file comprehensive.c.

92 {
93 (void)encoder;
94 (void)width;
95 (void)height;
96 (void)pixel_data;
97 (void)out_data;
98 (void)out_len;
99 return SET_ERRNO(ERROR_NOT_SUPPORTED, "H.265 encoding not supported in WASM");
100}

References ERROR_NOT_SUPPORTED, and SET_ERRNO.

Referenced by acip_send_image_frame_h265(), h265_client_capture_and_encode(), and threaded_send_image_frame_h265().

◆ h265_encoder_destroy()

void h265_encoder_destroy ( h265_encoder_t *  encoder)

Destroy an x265 encoder

Parameters
encoderEncoder to destroy (may be NULL)

Definition at line 102 of file comprehensive.c.

102 {
103 (void)encoder;
104}

Referenced by h265_client_context_create(), and h265_client_context_destroy().

◆ h265_encoder_flush()

asciichat_error_t h265_encoder_flush ( h265_encoder_t *  encoder,
uint8_t *  output_buf,
size_t *  output_size 
)

Flush remaining buffered frames from encoder

Sends a NULL frame to the encoder to flush all buffered frames. This should be called before destroying the encoder or when you need to ensure all encoded data is retrieved.

Parameters
encoderEncoder handle
output_bufBuffer for encoded output
output_sizeInput: buffer size, Output: actual encoded size
Returns
Error code (ASCIICHAT_OK on success, ASCIICHAT_OK with size=0 when no more data)

USAGE: // After final h265_encode() call, flush remaining frames while (size > 0) { size = max_size; h265_encoder_flush(encoder, buf, &size); if (size > 0) { // Send the flushed frame... } }

Definition at line 106 of file comprehensive.c.

106 {
107 (void)encoder;
108 (void)out_data;
109 (void)out_len;
110 return ASCIICHAT_OK;
111}

References ASCIICHAT_OK.

Referenced by protocol_stop_connection().

◆ h265_encoder_request_keyframe()

void h265_encoder_request_keyframe ( h265_encoder_t *  encoder)

Request a keyframe on the next encode

Forces the encoder to produce an I-frame (keyframe) on the next call to h265_encoder_encode(). Useful for error recovery or stream synchronization.

Parameters
encoderEncoder handle

Definition at line 113 of file comprehensive.c.

113 {
114 (void)encoder;
115}

Referenced by h265_client_request_keyframe().

◆ lifecycle_destroy_commit()

void lifecycle_destroy_commit ( lifecycle_t *  lc)

Commit successful destruction: DESTROYING → UNINITIALIZED. Call this after lifecycle_destroy_once() returns true and destroy work completes.

Parameters
lclifecycle state

Returns the module to UNINITIALIZED state, allowing future re-initialization.

Definition at line 275 of file comprehensive.c.

275 {
276 (void)lc;
277}

◆ lifecycle_destroy_once()

bool lifecycle_destroy_once ( lifecycle_t *  lc)

Lock-free concurrent destruction: CAS INITIALIZED → DESTROYING.

Winner receives true and must complete the two-phase sequence:

  1. Do actual destroy work
  2. Call lifecycle_destroy_commit() on completion

Losing callers return false and should skip cleanup work. Once destruction begins, no further operations are possible until the winner completes.

Parameters
lclifecycle state
Returns
true if THIS caller won the destroy race and should do work
false if not INITIALIZED, already being destroyed, or in DEAD state

Safe for concurrent callers. Exactly one caller gets true (the CAS winner). Prevents double-join and other double-cleanup issues when multiple threads call cleanup functions concurrently.

Definition at line 279 of file comprehensive.c.

279 {
280 (void)lc;
281 return true;
282}

◆ lifecycle_reset()

bool lifecycle_reset ( lifecycle_t *  lc)

Reset initialized module: INITIALIZED → UNINITIALIZED.

Parameters
lclifecycle state (may include sync_type and sync pointer)
Returns
true if THIS caller should do reset work
false if not INITIALIZED or in DEAD state

Allows re-initialization after reset (like shutdown, but keeps sync primitives). If lc->sync_type != SYNC_NONE, destroys the sync primitive (will be recreated on next init). Used for modules that support reset/reinit cycles (e.g., client crypto reconnect).

Definition at line 284 of file comprehensive.c.

284 {
285 (void)lc;
286 return true;
287}

◆ parse_private_key()

asciichat_error_t parse_private_key ( const char *  key_data,
size_t  key_len 
)

Definition at line 315 of file comprehensive.c.

315 {
316 (void)key_data;
317 (void)key_len;
318 return SET_ERRNO(ERROR_CRYPTO_KEY, "Private key parsing not supported in WASM");
319}

References ERROR_CRYPTO_KEY, and SET_ERRNO.

◆ pubkey_to_hex()

void pubkey_to_hex ( const uint8_t  pubkey[32],
char  hex_out[65] 
)

Convert Ed25519 public key to hex string.

Converts 32-byte binary pubkey to lowercase hex (64 characters).

Parameters
pubkeyBinary public key (32 bytes)
hex_outOutput hex string buffer (must be at least 65 bytes)

Definition at line 333 of file comprehensive.c.

333 {
334 (void)pubkey;
335 if (hex_out) {
336 hex_out[0] = '\0';
337 }
338}

◆ thread_pool_spawn()

asciichat_error_t thread_pool_spawn ( thread_pool_t *  pool,
void *(*)(void *)  thread_func,
void *  thread_arg,
int  stop_id,
const char *  thread_name 
)

Spawn a worker thread in the pool.

Creates and tracks a new worker thread with optional ordered cleanup. Threads are inserted into the pool's linked list in sorted order by stop_id (ascending). When the pool is stopped, threads with lower stop_id values are stopped first.

Stop ID Ordering Guidelines:

  • stop_id < 0: Unordered (stopped last, order undefined)
  • stop_id = 0: General background workers
  • stop_id = 1: Data source threads (e.g., receive, capture)
  • stop_id = 2: Processing threads (e.g., render, encode)
  • stop_id = 3: Data sink threads (e.g., send, write)

Example (Server Per-Client Threads):

  • stop_id=1: Receive thread (stop first to prevent new data)
  • stop_id=2: Render threads (stop after receive)
  • stop_id=3: Send thread (stop last after all processing)
Parameters
poolThread pool to spawn into
thread_funcThread function to execute
thread_argArgument passed to thread function
stop_idCleanup order (-1=unordered, 0+=ordered)
thread_nameThread name for debugging (max 63 chars, NULL=auto-generate)
Returns
ASCIICHAT_OK on success, error code on failure

Definition at line 342 of file comprehensive.c.

343 {
344 (void)pool;
345 (void)thread_func;
346 (void)thread_arg;
347 (void)stop_id;
348 (void)name;
349 return ASCIICHAT_OK; // No-op in WASM (no real threads)
350}
buffer_pool_t * pool

References ASCIICHAT_OK, and pool.

Referenced by acds_server_init(), audio_sender_init(), audio_start_thread(), capture_start_thread(), keepalive_start_thread(), protocol_start_connection(), server_main(), and tcp_server_spawn_thread().

◆ thread_pool_stop_all()

asciichat_error_t thread_pool_stop_all ( thread_pool_t *  pool)

Stop all threads in the pool in stop_id order.

Joins all threads in ascending stop_id order (lower values first). Threads with negative stop_id are stopped last in undefined order. This function blocks until all threads have exited.

Shutdown Sequence:

  1. Threads with stop_id >= 0 are joined in ascending order
  2. Threads with stop_id < 0 are joined in any order
  3. All thread entries are freed

After this call, the pool is empty but still valid - you can spawn new threads or destroy the pool.

Parameters
poolThread pool to stop
Returns
ASCIICHAT_OK on success, error code on failure

Definition at line 352 of file comprehensive.c.

352 {
353 (void)pool;
354 return ASCIICHAT_OK; // No-op in WASM
355}

References ASCIICHAT_OK, and pool.

Referenced by protocol_stop_connection(), and tcp_server_stop_client_threads().

◆ wav_dump_enabled()

bool wav_dump_enabled ( void  )

Check if audio dumping is enabled via environment.

Returns
true if ASCIICHAT_DUMP_AUDIO=1

Definition at line 237 of file comprehensive.c.

237 {
238 return false;
239}

◆ wav_writer_close()

void wav_writer_close ( void *  wav)

Definition at line 253 of file comprehensive.c.

253 {
254 (void)wav;
255}

◆ wav_writer_open()

void * wav_writer_open ( const char *  path)

Definition at line 241 of file comprehensive.c.

241 {
242 (void)path;
243 return NULL;
244}

◆ wav_writer_write()

int wav_writer_write ( wav_writer_t *  writer,
const float *  samples,
int  num_samples 
)

Write audio samples to WAV file.

Parameters
writerWAV writer context
samplesFloat samples in range [-1.0, 1.0]
num_samplesNumber of samples to write
Returns
0 on success, -1 on error

Definition at line 246 of file comprehensive.c.

246 {
247 (void)writer;
248 (void)samples;
249 (void)num_samples;
250 return 0;
251}

◆ webrtc_peer_manager_handle_ice()

int webrtc_peer_manager_handle_ice ( webrtc_peer_manager_t *  mgr,
const char *  candidate 
)

Definition at line 267 of file comprehensive.c.

267 {
268 (void)mgr;
269 (void)candidate;
270 return -1;
271}

◆ webrtc_peer_manager_handle_sdp()

asciichat_error_t webrtc_peer_manager_handle_sdp ( webrtc_peer_manager_t *  mgr,
const char *  sdp 
)

Definition at line 261 of file comprehensive.c.

261 {
262 (void)mgr;
263 (void)sdp;
264 return SET_ERRNO(ERROR_NOT_SUPPORTED, "WebRTC not supported in WASM");
265}

References ERROR_NOT_SUPPORTED, and SET_ERRNO.