ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
internal.h
Go to the documentation of this file.
1
6
7#ifndef ASCIICHAT_NETWORK_WEBSOCKET_INTERNAL_H
8#define ASCIICHAT_NETWORK_WEBSOCKET_INTERNAL_H
9
12#include <stdint.h>
13#include <stdbool.h>
14#include <stddef.h>
15#include <libplatform/atomic.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
30typedef struct {
32 size_t len;
34 uint8_t final;
36
38asciichat_error_t websocket_transport_send(acip_transport_t *transport, const void *data, size_t len);
39
40// Alias for backward compatibility
42
51typedef struct {
52 struct lws *wsi;
53 struct lws_context *context;
57 mutex_t recv_mutex;
58 cond_t recv_cond;
59 mutex_t send_mutex;
62 mutex_t state_mutex;
63 cond_t state_cond;
64
65 // Service thread for client-side transports
66 platform_thread_t service_thread;
68
69 // Partial message reassembly state (preserved across recv() calls)
70 // Fixes issue where slow fragment delivery caused reassembly timeouts
71 // and orphaned fragments in the queue
73 size_t partial_size;
78
82
83 // Graceful shutdown flag for thread-safe destruction
84 // When destroying the transport, this flag is set to true to signal all threads
85 // to exit send/recv operations before mutexes are destroyed.
89
91
93
94#endif // ASCIICHAT_NETWORK_WEBSOCKET_INTERNAL_H
95
96#ifdef __cplusplus
97}
98#endif
unsigned long long uint64_t
unsigned char uint8_t
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
struct acip_transport acip_transport_t
Forward declaration of ACIP transport.
Definition host.h:508
Transport abstraction layer for ACIP protocol.
asciichat_error_t websocket_transport_send(acip_transport_t *transport, const void *data, size_t len)
void websocket_transport_write_pending(struct lws *wsi, websocket_transport_data_t *ws_data)
Drain client messages from the send queue on the service thread.
websocket_msg_t websocket_recv_msg_t
Definition internal.h:41
Lock-Free Ring Buffer and Frame Buffer Management.
Atomic value wrapper for integral/boolean types.
Definition atomic.h:76
Audio ring buffer for real-time audio streaming.
Definition ringbuffer.h:94
Owned WebSocket frame queued for sending or reassembly.
Definition internal.h:30
size_t len
Frame length in bytes.
Definition internal.h:32
uint8_t first
1 if first frame of message (or complete message)
Definition internal.h:33
uint8_t * data
Frame data (allocated, caller must free).
Definition internal.h:31
Private state for one libwebsockets-backed ACIP transport.
Definition internal.h:51
platform_thread_t service_thread
Thread that services libwebsockets context.
Definition internal.h:66
bool reassembling
True if currently assembling a message.
Definition internal.h:77
struct lws_context * context
libwebsockets context (may be owned or borrowed)
Definition internal.h:53
mutex_t send_mutex
Protect send_queue operations only.
Definition internal.h:59
bool owns_context
True if transport owns context (client), false if borrowed (server).
Definition internal.h:54
cond_t recv_cond
Signal when recv_queue messages arrive.
Definition internal.h:58
mutex_t state_mutex
Protect state changes.
Definition internal.h:62
uint8_t * inflight_buffer
Owned until the next writable callback or teardown.
Definition internal.h:81
bool service_running
Owner must join the service thread before freeing storage.
Definition internal.h:67
ringbuffer_t * send_queue
Send message queue (for server-side transports).
Definition internal.h:56
size_t partial_capacity
Capacity of partial buffer.
Definition internal.h:74
struct lws * wsi
libwebsockets instance (owned)
Definition internal.h:52
ringbuffer_t * recv_queue
Receive message queue.
Definition internal.h:55
size_t partial_size
Current size of partial buffer.
Definition internal.h:73
cond_t state_cond
Signal when is_connected changes (for connection wait).
Definition internal.h:63
bool connection_failed
Connection attempt failed (for client-side detection).
Definition internal.h:61
bool is_connected
Connection state.
Definition internal.h:60
mutex_t recv_mutex
Protect recv_queue operations only.
Definition internal.h:57
size_t pending_send_bytes
Includes the inflight owner until writable completion.
Definition internal.h:79
int fragment_count
Fragment count for current reassembly.
Definition internal.h:76
uint64_t reassembly_start_ns
Start time of current reassembly (for timeout detection).
Definition internal.h:75
uint8_t * partial_buffer
Partial message buffer being assembled.
Definition internal.h:72
atomic_t is_destroying
True when destruction has started.
Definition internal.h:88