ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
memory.h File Reference

🧠 In-memory rate limiting backend interface More...

Go to the source code of this file.

Functions

void * memory_backend_create (void)
 Create memory backend instance.
 
uint64_t rate_limiter_get_time_ms (void)
 Helper: Get current time in milliseconds.
 
const char * rate_limiter_event_type_string (rate_event_type_t event_type)
 Helper: Get event type string for logging.
 

Variables

const rate_limiter_backend_ops_t memory_backend_ops
 Memory backend operations vtable.
 

Detailed Description

🧠 In-memory rate limiting backend interface

Definition in file network/rate_limit/memory.h.

Function Documentation

◆ memory_backend_create()

void * memory_backend_create ( void  )

Create memory backend instance.

Returns
Backend instance or NULL on failure

Definition at line 238 of file network/rate_limit/memory.c.

238 {
240 if (!backend) {
241 log_error("Failed to allocate memory backend");
242 return NULL;
243 }
244
245 memset(backend, 0, sizeof(*backend));
246
247 if (mutex_init(&backend->lock) != 0) {
248 log_error("Failed to initialize mutex");
249 SAFE_FREE(backend);
250 return NULL;
251 }
252
253 log_debug("Memory rate limiter backend initialized");
254 return backend;
255}
#define SAFE_FREE(ptr)
Definition common.h:320
#define SAFE_MALLOC(size, cast)
Definition common.h:208
#define log_error(...)
Log an ERROR message.
#define log_debug(...)
Log a DEBUG message.
int mutex_init(mutex_t *mutex)
Initialize a mutex.
Memory backend data.
mutex_t lock
Mutex for thread safety.

References memory_backend_t::lock, log_debug, log_error, mutex_init(), SAFE_FREE, and SAFE_MALLOC.

Referenced by rate_limiter_create_memory().

◆ rate_limiter_event_type_string()

const char * rate_limiter_event_type_string ( rate_event_type_t  event_type)

Helper: Get event type string for logging.

Helper: Get event type string for logging.

Definition at line 184 of file rate_limit.c.

184 {
185 if (event_type >= RATE_EVENT_MAX) {
186 return "unknown";
187 }
188 return event_type_strings[event_type];
189}
@ RATE_EVENT_MAX
Sentinel value.
Definition rate_limit.h:60

References RATE_EVENT_MAX.

◆ rate_limiter_get_time_ms()

uint64_t rate_limiter_get_time_ms ( void  )

Helper: Get current time in milliseconds.

Helper: Get current time in milliseconds.

Definition at line 175 of file rate_limit.c.

175 {
176 struct timespec ts;
177 clock_gettime(CLOCK_REALTIME, &ts);
178 return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
179}
unsigned long long uint64_t
Definition common.h:59

Variable Documentation

◆ memory_backend_ops

const rate_limiter_backend_ops_t memory_backend_ops
extern

Memory backend operations vtable.

Definition at line 257 of file network/rate_limit/memory.c.

257 {
258 .check = memory_check,
259 .record = memory_record,
260 .cleanup = memory_cleanup,
261 .destroy = memory_destroy,
262};

Referenced by rate_limiter_create_memory().