C Collections

chttpserver · Section 3

chttpsvr_set_engine_mem_mgmt_procs

chttpsvr_set_engine_mem_mgmt_procs - set custom memory management for engine-level allocations

C Collections (libccollections, -lccollections)

#include <ccollections/chttpserver.h>
 
ccol_retval chttpsvr_set_engine_mem_mgmt_procs(ccol_memmgmt_procs *mp);

Sends every allocation of the shared ceventloop reactor through
the malloc, free, calloc and realloc that mp holds.  That covers the
construction of the reactor and the record it keeps for each
connection registration, and it works like the memory management
procs that every other module of the library accepts.  A NULL mp
puts the default allocator back.
 
Each chttpsvr instance has its own allocator for its own connections
and requests, which you give to chttpsvr_create_mp by the usual _mp
convention.  This function is separate from that allocator and only
affects the construction of the one shared reactor.
 
You can call it only before the first chttpsvr_start of the process.
Once the reactor has allocated memory with one set of procs, a switch
to another malloc and free pair corrupts the heap.  It may be called
again after the reactor has stopped completely, which means after
chttpsvr_engine_wait returns, and before the next chttpsvr_start.
 
When mp is not NULL, all four function pointers (malloc, free,
calloc and realloc) must be set.

ccol_success on success.
ccol_invalid_args when mp is not NULL but has a NULL function pointer.
ccol_not_permitted when the reactor is already running.  Stop it
                  first.

chttpsvr_set_engine_logger(3), chttpsvr_set_engine_num_reactor_threads(3), chttpsvr_start(3), chttpsvr_engine_stop(3), chttpsvr_engine_wait(3)