mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
lws_dll[2]_foreach_safe: add user cb param
The callback flow is a bit more disruptive than doing the iteration directly in your function. This helps by passing a user void * into the callback set as an lws_dll[2]_foreach_safe() arg.
This commit is contained in:
parent
b227d10187
commit
13ae9927a3
4 changed files with 26 additions and 8 deletions
|
@ -213,7 +213,8 @@ lws_dll_remove_track_tail(struct lws_dll *d, struct lws_dll *phead);
|
|||
/* another way to do lws_start_foreach_dll_safe() on a list via a cb */
|
||||
|
||||
LWS_VISIBLE LWS_EXTERN int
|
||||
lws_dll_foreach_safe(struct lws_dll *phead, int (*cb)(struct lws_dll *d));
|
||||
lws_dll_foreach_safe(struct lws_dll *phead, void *user,
|
||||
int (*cb)(struct lws_dll *d, void *user));
|
||||
|
||||
#define lws_dll_is_detached(___dll, __head) \
|
||||
(!(___dll)->prev && !(___dll)->next && (__head)->prev != (___dll))
|
||||
|
@ -274,7 +275,8 @@ LWS_VISIBLE LWS_EXTERN void
|
|||
lws_dll2_remove(struct lws_dll2 *d);
|
||||
|
||||
LWS_VISIBLE LWS_EXTERN int
|
||||
lws_dll2_foreach_safe(struct lws_dll2_owner *owner, int (*cb)(struct lws_dll2 *d));
|
||||
lws_dll2_foreach_safe(struct lws_dll2_owner *owner, void *user,
|
||||
int (*cb)(struct lws_dll2 *d, void *user));
|
||||
|
||||
/*
|
||||
* these are safe against the current container object getting deleted,
|
||||
|
|
|
@ -120,7 +120,7 @@ lws_remove_child_from_any_parent(struct lws *wsi)
|
|||
|
||||
#if !defined(LWS_NO_CLIENT)
|
||||
static int
|
||||
lws_close_trans_q_leader(struct lws_dll2 *d)
|
||||
lws_close_trans_q_leader(struct lws_dll2 *d, void *user)
|
||||
{
|
||||
struct lws *w = lws_container_of(d, struct lws, dll2_cli_txn_queue);
|
||||
|
||||
|
@ -165,7 +165,7 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason,
|
|||
if ((int)reason != -1)
|
||||
lws_vhost_lock(wsi->vhost);
|
||||
|
||||
lws_dll2_foreach_safe(&wsi->dll2_cli_txn_queue_owner,
|
||||
lws_dll2_foreach_safe(&wsi->dll2_cli_txn_queue_owner, NULL,
|
||||
lws_close_trans_q_leader);
|
||||
|
||||
/*
|
||||
|
|
|
@ -263,10 +263,11 @@ lws_dll_remove_track_tail(struct lws_dll *d, struct lws_dll *phead)
|
|||
|
||||
|
||||
int
|
||||
lws_dll_foreach_safe(struct lws_dll *phead, int (*cb)(struct lws_dll *d))
|
||||
lws_dll_foreach_safe(struct lws_dll *phead, void *user,
|
||||
int (*cb)(struct lws_dll *d, void *user))
|
||||
{
|
||||
lws_start_foreach_dll_safe(struct lws_dll *, p, tp, phead->next) {
|
||||
if (cb(p))
|
||||
if (cb(p, user))
|
||||
return 1;
|
||||
} lws_end_foreach_dll_safe(p, tp);
|
||||
|
||||
|
@ -274,10 +275,11 @@ lws_dll_foreach_safe(struct lws_dll *phead, int (*cb)(struct lws_dll *d))
|
|||
}
|
||||
|
||||
int
|
||||
lws_dll2_foreach_safe(struct lws_dll2_owner *owner, int (*cb)(struct lws_dll2 *d))
|
||||
lws_dll2_foreach_safe(struct lws_dll2_owner *owner, void *user,
|
||||
int (*cb)(struct lws_dll2 *d, void *user))
|
||||
{
|
||||
lws_start_foreach_dll_safe(struct lws_dll2 *, p, tp, owner->head) {
|
||||
if (cb(p))
|
||||
if (cb(p, user))
|
||||
return 1;
|
||||
} lws_end_foreach_dll_safe(p, tp);
|
||||
|
||||
|
|
|
@ -1978,9 +1978,23 @@ rops_destroy_vhost_ws(struct lws_vhost *vh)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if defined(LWS_WITH_HTTP_PROXY)
|
||||
static int
|
||||
ws_destroy_proxy_buf(struct lws_dll *d, void *user)
|
||||
{
|
||||
lws_free(d);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
rops_destroy_role_ws(struct lws *wsi)
|
||||
{
|
||||
#if defined(LWS_WITH_HTTP_PROXY)
|
||||
lws_dll_foreach_safe(&wsi->ws->proxy_head, NULL, ws_destroy_proxy_buf);
|
||||
#endif
|
||||
|
||||
lws_free_set_NULL(wsi->ws);
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue