|
libwebsockets
Lightweight C library for HTML5 websockets
|
Lws supports two kinds of doubly-linked list, lws_dll and lws_dll2.
Unless memory is at a big premium, or it has to work on lws < v3.2, it's best to simply use lws_dll2.
The basics are the same for lws_dll and lws_dll2.
The list objects point only to themselves, and you use the lws_container_of macro to get a pointer to your struct that contains the list object. Doing it this way
Adding a mystruct to the owner list (...add_tail() works the same way but adds to the other end of the list)
Removing the list object from its owner
If you have a struct lws_dll *d pointing to list in struct mystruct, you can convert it to a struct mystruct *p ike this
Adding a mystruct to the owner list (...add_tail() works the same way but adds to the other end of the list)
Removing the list object from its owner (notice compared to lws_dll, it doesn't need to be told the owner)
If you have a struct lws_dll2 *d pointing to list in struct mystruct, you can convert it to a struct mystruct *p ike this
| function | lws_dll | lws_dll2 |
|---|---|---|
| add entry at head | void lws_dll_add_head(struct lws_dll *d, struct lws_dll *phead) | void lws_dll2_add_head(struct lws_dll2 *d, struct lws_dll2_owner *owner) |
| add entry at tail | void lws_dll_add_tail(struct lws_dll *d, struct lws_dll *phead); | void lws_dll2_add_tail(struct lws_dll2 *d, struct lws_dll2_owner *owner) |
| remove entry from its owning list | void lws_dll_remove_track_tail(struct lws_dll *d, struct lws_dll *phead) | void lws_dll2_add_tail(struct lws_dll2 *d, struct lws_dll2_owner *owner) |
| get owner | (not supported) | struct lws_dll2_owner * lws_dll2_owner(const struct lws_dll2 *d) |
| check if item is detached from any list | lws_dll_is_detached(struct lws_dll *d, struct lws_dll *phead) \ilinebr </td> <td class="markdownTableBodyNone"> int lws_dll2_is_detached(const struct lws_dll2 *d) | |
| iterate through items on list | int lws_dll_foreach_safe(struct lws_dll *phead, void *user, int (*cb)(struct lws_dll *d, void *user)) \ilinebr </td> <td class="markdownTableBodyNone"> int lws_dll2_foreach_safe(struct lws_dll2_owner *owner, void *user, int (*cb)(struct lws_dll2 *d, void *user)) |