ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
network/websocket/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
26typedef struct {
28 size_t len;
30 uint8_t final;
32
34asciichat_error_t websocket_transport_send(acip_transport_t *transport, const void *data, size_t len);
35
36// Alias for backward compatibility
38
47typedef struct {
48 struct lws *wsi;
49 struct lws_context *context;
53 mutex_t recv_mutex;
54 cond_t recv_cond;
55 mutex_t send_mutex;
58 mutex_t state_mutex;
59 cond_t state_cond;
60
61 // Service thread for client-side transports
62 platform_thread_t service_thread;
64
65 // Partial message reassembly state (preserved across recv() calls)
66 // Fixes issue where slow fragment delivery caused reassembly timeouts
67 // and orphaned fragments in the queue
69 size_t partial_size;
74
78
79 // Graceful shutdown flag for thread-safe destruction
80 // When destroying the transport, this flag is set to true to signal all threads
81 // to exit send/recv operations before mutexes are destroyed.
84 atomic_t is_destroying;
85
87
89
90#endif // ASCIICHAT_NETWORK_WEBSOCKET_INTERNAL_H
unsigned long long uint64_t
Definition common.h:63
unsigned char uint8_t
Definition common.h:60
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:44
struct acip_transport acip_transport_t
Forward declaration of ACIP transport.
Definition host.h:506
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
Lock-Free Ring Buffer and Frame Buffer Management.
Audio ring buffer for real-time audio streaming.
Definition ringbuffer.h:90
Owned WebSocket frame queued for sending or reassembly.
size_t len
Frame length in bytes.
uint8_t first
1 if first frame of message (or complete message)
uint8_t * data
Frame data (allocated, caller must free).
Private state for one libwebsockets-backed ACIP transport.
platform_thread_t service_thread
Thread that services libwebsockets context.
bool reassembling
True if currently assembling a message.
struct lws_context * context
libwebsockets context (may be owned or borrowed)
mutex_t send_mutex
Protect send_queue operations only.
bool owns_context
True if transport owns context (client), false if borrowed (server).
cond_t recv_cond
Signal when recv_queue messages arrive.
mutex_t state_mutex
Protect state changes.
uint8_t * inflight_buffer
Owned until the next writable callback or teardown.
bool service_running
Owner must join the service thread before freeing storage.
ringbuffer_t * send_queue
Send message queue (for server-side transports).
size_t partial_capacity
Capacity of partial buffer.
struct lws * wsi
libwebsockets instance (owned)
ringbuffer_t * recv_queue
Receive message queue.
size_t partial_size
Current size of partial buffer.
cond_t state_cond
Signal when is_connected changes (for connection wait).
bool connection_failed
Connection attempt failed (for client-side detection).
mutex_t recv_mutex
Protect recv_queue operations only.
size_t pending_send_bytes
Includes the inflight owner until writable completion.
int fragment_count
Fragment count for current reassembly.
uint64_t reassembly_start_ns
Start time of current reassembly (for timeout detection).
uint8_t * partial_buffer
Partial message buffer being assembled.
atomic_t is_destroying
True when destruction has started.