ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
network/websocket/internal.h
Go to the documentation of this file.
1
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 <ascii-chat/atomic.h>
16
24typedef struct {
26 size_t len;
28 uint8_t final;
30
31// Alias for backward compatibility
33
39typedef struct {
41 size_t size;
43
47typedef struct {
48 struct lws *wsi;
49 struct lws_context *context;
62
63 // Service thread for client-side transports
65 volatile bool service_running;
66
67 // Partial message reassembly state (preserved across recv() calls)
68 // Fixes issue where slow fragment delivery caused reassembly timeouts
69 // and orphaned fragments in the queue
71 size_t partial_size;
76
77 // Deferred buffer freeing for compression layer compatibility
78 // permessage-deflate holds buffer references asynchronously after lws_write()
79 // We defer freeing to prevent use-after-free in the compression layer
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.
87
89
90#endif // ASCIICHAT_NETWORK_WEBSOCKET_INTERNAL_H
Platform abstraction layer umbrella header providing unified cross-platform API.
⚛️ Atomic operations abstraction layer with debug tracking
unsigned long long uint64_t
Definition common.h:59
unsigned char uint8_t
Definition common.h:56
void * asciichat_thread_t
websocket_msg_t websocket_recv_msg_t
Lock-Free Ring Buffer and Frame Buffer Management.
ClangTool/LibTooling compatibility shim for stdbool.h.
Atomic value wrapper for integral/boolean types.
Definition atomic.h:76
Condition variable type (POSIX: pthread_cond_t with debug tracking)
Definition cond.h:63
Mutex type (POSIX: pthread_mutex_t with debug tracking)
Pending buffer free item for deferred cleanup Used to defer buffer freeing when permessage-deflate co...
uint8_t * ptr
Pointer to buffer to free.
Lock-free ring buffer structure.
Definition ringbuffer.h:88
WebSocket message element (individual frame or fragment)
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)
WebSocket transport implementation data.
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.
ringbuffer_t * send_queue
Send message queue (for server-side transports)
ringbuffer_t * pending_free_queue
Queue of buffers pending delayed free.
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.
size_t send_buffer_capacity
Current send buffer capacity.
cond_t state_cond
Signal when is_connected changes (for connection wait)
uint8_t * send_buffer
Send buffer with LWS_PRE padding.
bool connection_failed
Connection attempt failed (for client-side detection)
mutex_t pending_free_mutex
Protect pending_free_queue operations.
mutex_t recv_mutex
Protect recv_queue operations only.
asciichat_thread_t service_thread
Thread that services libwebsockets context.
int fragment_count
Fragment count for current reassembly.
uint64_t reassembly_start_ns
Start time of current reassembly (for timeout detection)
volatile bool service_running
Service thread running flag.
uint8_t * partial_buffer
Partial message buffer being assembled.
atomic_t is_destroying
True when destruction has started.