libwebsockets
Lightweight C library for HTML5 websockets
|
Go to the source code of this file.
Data Structures | |
struct | lws_map_info |
Macros | |
#define | lws_map_item_create_ks(_map, _str, _v, _vl) |
#define | lws_map_item_lookup_ks(_map, _str) lws_map_item_lookup(_map, (const lws_map_key_t)_str, strlen(_str)) |
Typedefs | |
typedef struct lws_map | lws_map_t |
typedef void * | lws_map_key_t |
typedef void * | lws_map_value_t |
typedef uint32_t | lws_map_hash_t |
typedef lws_map_hash_t(* | lws_map_hash_from_key_t) (const lws_map_key_t key, size_t kl) |
typedef int(* | lws_map_compare_key_t) (const lws_map_key_t key1, size_t kl1, const lws_map_value_t key2, size_t kl2) |
typedef void *(* | lws_map_alloc_t) (struct lws_map *mo, size_t x) |
typedef void(* | lws_map_free_t) (void *) |
typedef struct lws_map_info | lws_map_info_t |
Functions | |
LWS_VISIBLE LWS_EXTERN const void * | lws_map_item_key (struct lws_map_item *_item) |
LWS_VISIBLE LWS_EXTERN const void * | lws_map_item_value (struct lws_map_item *_item) |
LWS_VISIBLE LWS_EXTERN size_t | lws_map_item_key_len (struct lws_map_item *_item) |
LWS_VISIBLE LWS_EXTERN size_t | lws_map_item_value_len (struct lws_map_item *_item) |
LWS_VISIBLE LWS_EXTERN lws_map_t * | lws_map_create (const lws_map_info_t *info) |
LWS_VISIBLE LWS_EXTERN void * | lws_map_alloc_lwsac (struct lws_map *map, size_t x) |
LWS_VISIBLE LWS_EXTERN void | lws_map_free_lwsac (void *v) |
LWS_VISIBLE LWS_EXTERN void | lws_map_destroy (lws_map_t **pmap) |
LWS_VISIBLE LWS_EXTERN struct lws_map_item * | lws_map_item_create (lws_map_t *map, const lws_map_key_t key, size_t keylen, const lws_map_value_t value, size_t valuelen) |
LWS_VISIBLE LWS_EXTERN void | lws_map_item_destroy (struct lws_map_item *item) |
LWS_VISIBLE LWS_EXTERN struct lws_map_item * | lws_map_item_lookup (lws_map_t *map, const lws_map_key_t key, size_t keylen) |
struct lws_map_info |
Data Fields | ||
---|---|---|
lws_map_hash_from_key_t | _hash | |
lws_map_compare_key_t | _compare | |
lws_map_alloc_t | _alloc | |
lws_map_free_t | _free | |
void * | opaque |
&lwsac if using lwsac allocator |
void * | aux |
chunk size if using lwsac allocator this can be used by the alloc handler, eg for lws_ac |
size_t | modulo |
number of hashed owner lists to create |
#define lws_map_item_create_ks | ( | _map, | |
_str, | |||
_v, | |||
_vl | |||
) |
#define lws_map_item_lookup_ks | ( | _map, | |
_str | |||
) | lws_map_item_lookup(_map, (const lws_map_key_t)_str, strlen(_str)) |
typedef void* lws_map_key_t |
typedef void* lws_map_value_t |
typedef uint32_t lws_map_hash_t |
typedef lws_map_hash_t(* lws_map_hash_from_key_t) (const lws_map_key_t key, size_t kl) |
typedef int(* lws_map_compare_key_t) (const lws_map_key_t key1, size_t kl1, const lws_map_value_t key2, size_t kl2) |
typedef void*(* lws_map_alloc_t) (struct lws_map *mo, size_t x) |
typedef struct lws_map_info lws_map_info_t |
LWS_VISIBLE LWS_EXTERN const void* lws_map_item_key | ( | struct lws_map_item * | _item | ) |
LWS_VISIBLE LWS_EXTERN const void* lws_map_item_value | ( | struct lws_map_item * | _item | ) |
LWS_VISIBLE LWS_EXTERN size_t lws_map_item_key_len | ( | struct lws_map_item * | _item | ) |
LWS_VISIBLE LWS_EXTERN size_t lws_map_item_value_len | ( | struct lws_map_item * | _item | ) |
LWS_VISIBLE LWS_EXTERN lws_map_t* lws_map_create | ( | const lws_map_info_t * | info | ) |
lws_map_create() - create a map object and hashtables on heap
info | description of map to create |
Creates a map object on heap, using lws_malloc().
info
may be all zeros inside, if so, modulo defaults to 8, and the operation callbacks default to using lws_malloc() / _free() for item alloc, a default xor / shift based hash and simple linear memory key compare.
For less typical use-cases, the provided info
members can be tuned to control how the allocation of mapped items is done, lws provides two exports lws_map_alloc_lwsac() and lws_map_free_lwsac() that can be used for _alloc and _free to have items allocated inside an lwsac.
The map itself is created on the heap directly, the info._alloc() op is only used when creating items.
keys have individual memory sizes and do not need to all be the same length.
LWS_VISIBLE LWS_EXTERN void* lws_map_alloc_lwsac | ( | struct lws_map * | map, |
size_t | x | ||
) |
LWS_VISIBLE LWS_EXTERN void lws_map_free_lwsac | ( | void * | v | ) |
LWS_VISIBLE LWS_EXTERN void lws_map_destroy | ( | lws_map_t ** | pmap | ) |
lws_map_destroy() - deallocate all items and free map
pmap | pointer to pointer map object to deallocate |
Frees all items in the map, using info._free(), and then frees the map from heap directly. *pmap
is set to NULL.
LWS_VISIBLE LWS_EXTERN struct lws_map_item* lws_map_item_create | ( | lws_map_t * | map, |
const lws_map_key_t | key, | ||
size_t | keylen, | ||
const lws_map_value_t | value, | ||
size_t | valuelen | ||
) |
lws_map_item_create() - allocate and map an item into an existing map
map | the map to add items into |
key | the key, may be any kind of object |
keylen | the length of the key in bytes |
value | the value, may be any kind of object |
valuelen | the length of value |
Allocates space for the item, key and value using the map allocator, and if non-NULL, copies the key and value into the item.
If an item with the same key exists, it is removed and destroyed before creating and adding the new one.
LWS_VISIBLE LWS_EXTERN void lws_map_item_destroy | ( | struct lws_map_item * | item | ) |
lws_map_item_destroy() - remove item from map and free
item | the item in the map to remove and free |
LWS_VISIBLE LWS_EXTERN struct lws_map_item* lws_map_item_lookup | ( | lws_map_t * | map, |
const lws_map_key_t | key, | ||
size_t | keylen | ||
) |
lws_map_item_lookup() - look for a item with the given key in the map
map | the map |
key | the key to look for |
keylen | the length of the key to look for |
Searches for the key in the map, using the map's key hash and key compare functions.