libwebsockets
Lightweight C library for HTML5 websockets
Toggle main menu visibility
Loading...
Searching...
No Matches
lws-dll2.h
Go to the documentation of this file.
1
/*
2
* libwebsockets - small server side websockets and web server implementation
3
*
4
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a copy
7
* of this software and associated documentation files (the "Software"), to
8
* deal in the Software without restriction, including without limitation the
9
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
* sell copies of the Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
12
*
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
15
*
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
* IN THE SOFTWARE.
23
*/
24
31
48
#define lws_start_foreach_ll(type, it, start)\
49
{ \
50
type it = start; \
51
while (it) { \
52
int _c_##it = 0, _b_##it = 0; \
53
for (; !_c_##it; _c_##it = 1) {
54
68
69
#define lws_end_foreach_ll(it, nxt) \
70
_b_##it = 1; \
71
} \
72
if (!_b_##it) break; \
73
it = it->nxt; \
74
} \
75
}
76
96
#define lws_start_foreach_ll_safe(type, it, start, nxt)\
97
{ \
98
type next_##it; \
99
for (type it = start; it && ((next_##it = it->nxt), 1); it = next_##it) {
100
114
115
#define lws_end_foreach_ll_safe(it) \
116
} \
117
}
118
139
#define lws_start_foreach_llp(type, it, start)\
140
{ \
141
type it = &(start); \
142
while (*(it)) { \
143
int _c_##it = 0, _b_##it = 0; \
144
for (; !_c_##it; _c_##it = 1) {
145
146
#define lws_start_foreach_llp_safe(type, it, start, nxt)\
147
{ \
148
type next; \
149
for (type it = &(start); *(it) && ((next = &((*(it))->nxt)), 1); it = next) {
150
164
165
#define lws_end_foreach_llp(it, nxt) \
166
_b_##it = 1; \
167
} \
168
if (!_b_##it) break; \
169
it = &(*(it))->nxt; \
170
} \
171
}
172
173
#define lws_end_foreach_llp_safe(it) \
174
} \
175
}
176
177
#define lws_ll_fwd_insert(\
178
___new_object,
/* pointer to new object */
\
179
___m_list,
/* member for next list object ptr */
\
180
___list_head
/* list head */
\
181
) {\
182
___new_object->___m_list = ___list_head; \
183
___list_head = ___new_object; \
184
}
185
186
#define lws_ll_fwd_remove(\
187
___type,
/* type of listed object */
\
188
___m_list,
/* member for next list object ptr */
\
189
___target,
/* object to remove from list */
\
190
___list_head
/* list head */
\
191
) { \
192
lws_start_foreach_llp(___type **, ___ppss, ___list_head) { \
193
if (*___ppss == ___target) { \
194
*___ppss = ___target->___m_list; \
195
break; \
196
} \
197
} lws_end_foreach_llp(___ppss, ___m_list); \
198
}
199
200
201
/*
202
* doubly linked-list
203
*/
204
205
/*
206
* lws_dll2_owner / lws_dll2 : more capable version of lws_dll. Differences:
207
*
208
* - there's an explicit lws_dll2_owner struct which holds head, tail and
209
* count of members.
210
*
211
* - list members all hold a pointer to their owner. So user code does not
212
* have to track anything about exactly what lws_dll2_owner list the object
213
* is a member of.
214
*
215
* - you can use lws_dll unless you want the member count or the ability to
216
* not track exactly which list it's on.
217
*
218
* - layout is compatible with lws_dll (but lws_dll apis will not update the
219
* new stuff)
220
*/
221
222
223
struct
lws_dll2
;
224
struct
lws_dll2_owner
;
225
226
typedef
struct
lws_dll2
{
227
struct
lws_dll2
*
prev
;
228
struct
lws_dll2
*
next
;
229
struct
lws_dll2_owner
*
owner
;
230
}
lws_dll2_t
;
231
232
typedef
struct
lws_dll2_owner
{
233
struct
lws_dll2
*
tail
;
234
struct
lws_dll2
*
head
;
235
236
uint32_t
count
;
237
}
lws_dll2_owner_t
;
238
239
LWS_VISIBLE
LWS_EXTERN
int
240
lws_dll2_is_detached
(
const
struct
lws_dll2
*d);
241
242
static
LWS_INLINE
const
struct
lws_dll2_owner
*
243
lws_dll2_owner
(
const
struct
lws_dll2
*d) {
return
d->
owner
; }
244
245
static
LWS_INLINE
struct
lws_dll2
*
246
lws_dll2_get_head(
struct
lws_dll2_owner
*
owner
) {
return
owner
->
head
; }
247
248
static
LWS_INLINE
struct
lws_dll2
*
249
lws_dll2_get_tail(
struct
lws_dll2_owner
*
owner
) {
return
owner
->
tail
; }
250
251
LWS_VISIBLE
LWS_EXTERN
void
252
lws_dll2_add_head
(
struct
lws_dll2
*d,
struct
lws_dll2_owner
*
owner
);
253
254
LWS_VISIBLE
LWS_EXTERN
void
255
lws_dll2_add_tail
(
struct
lws_dll2
*d,
struct
lws_dll2_owner
*
owner
);
256
257
LWS_VISIBLE
LWS_EXTERN
void
258
lws_dll2_remove
(
struct
lws_dll2
*d);
259
260
typedef
int (*
lws_dll2_foreach_cb_t
)(
struct
lws_dll2
*d,
void
*user);
261
262
LWS_VISIBLE
LWS_EXTERN
int
263
lws_dll2_foreach_safe
(
struct
lws_dll2_owner
*
owner
,
void
*user,
264
lws_dll2_foreach_cb_t
cb);
265
266
LWS_VISIBLE
LWS_EXTERN
void
267
lws_dll2_clear
(
struct
lws_dll2
*d);
268
269
LWS_VISIBLE
LWS_EXTERN
void
270
lws_dll2_owner_clear
(
struct
lws_dll2_owner
*d);
271
272
LWS_VISIBLE
LWS_EXTERN
void
273
lws_dll2_add_before
(
struct
lws_dll2
*d,
struct
lws_dll2
*after);
274
275
LWS_VISIBLE
LWS_EXTERN
void
276
lws_dll2_add_insert
(
struct
lws_dll2
*d,
struct
lws_dll2
*
prev
);
277
278
LWS_VISIBLE
LWS_EXTERN
void
279
lws_dll2_add_sorted
(
lws_dll2_t
*d,
lws_dll2_owner_t
*own,
280
int
(*compare)(
const
lws_dll2_t
*d,
const
lws_dll2_t
*i));
281
282
LWS_VISIBLE
LWS_EXTERN
void
283
lws_dll2_add_sorted_priv
(
lws_dll2_t
*d,
lws_dll2_owner_t
*own,
void
*priv,
284
int
(*compare3)(
void
*priv,
const
lws_dll2_t
*d,
285
const
lws_dll2_t
*i));
286
287
LWS_VISIBLE
LWS_EXTERN
void
*
288
_lws_dll2_search_sz_pl
(
lws_dll2_owner_t
*own,
const
char
*name,
size_t
namelen,
289
size_t
dll2_ofs,
size_t
ptr_ofs);
290
291
/*
292
* Searches objects in an owner list linearly and returns one with a given
293
* member C-string matching a supplied length-provided string if it exists, else
294
* NULL.
295
*/
296
297
#define lws_dll2_search_sz_pl(own, name, namelen, type, membd2list, membptr) \
298
((type *)_lws_dll2_search_sz_pl(own, name, namelen, \
299
offsetof(type, membd2list), \
300
offsetof(type, membptr)))
301
302
#if defined(_DEBUG)
303
void
304
lws_dll2_describe
(
struct
lws_dll2_owner
*
owner
,
const
char
*desc);
305
#else
306
#define lws_dll2_describe(x, y)
307
#endif
308
309
/*
310
* these are safe against the current container object getting deleted,
311
* since the hold his next in a temp and go to that next. ___tmp is
312
* the temp.
313
*/
314
315
#define lws_start_foreach_dll_safe(___type, ___it, ___tmp, ___start) \
316
{ \
317
___type ___tmp; \
318
for (___type ___it = ___start; ___it && (((___tmp) = (___it)->next), 1); ___it = ___tmp) {
319
320
#define lws_end_foreach_dll_safe(___it, ___tmp) \
321
} \
322
}
323
324
#define lws_start_foreach_dll(___type, ___it, ___start) \
325
{ \
326
for (___type ___it = ___start; ___it; ___it = (___it)->next) {
327
328
#define lws_end_foreach_dll(___it) \
329
} \
330
}
331
333
lws_dll2_owner::tail
struct lws_dll2 * tail
Definition
lws-dll2.h:233
lws_dll2::next
struct lws_dll2 * next
Definition
lws-dll2.h:228
lws_dll2::owner
struct lws_dll2_owner * owner
Definition
lws-dll2.h:229
lws_dll2::prev
struct lws_dll2 * prev
Definition
lws-dll2.h:227
lws_dll2_owner::head
struct lws_dll2 * head
Definition
lws-dll2.h:234
lws_dll2_owner::count
uint32_t count
Definition
lws-dll2.h:236
lws_dll2_t
struct lws_dll2 lws_dll2_t
lws_dll2_add_tail
LWS_VISIBLE LWS_EXTERN void lws_dll2_add_tail(struct lws_dll2 *d, struct lws_dll2_owner *owner)
lws_dll2_owner_clear
LWS_VISIBLE LWS_EXTERN void lws_dll2_owner_clear(struct lws_dll2_owner *d)
lws_dll2_add_sorted_priv
LWS_VISIBLE LWS_EXTERN void lws_dll2_add_sorted_priv(lws_dll2_t *d, lws_dll2_owner_t *own, void *priv, int(*compare3)(void *priv, const lws_dll2_t *d, const lws_dll2_t *i))
lws_dll2_describe
#define lws_dll2_describe(x, y)
Definition
lws-dll2.h:306
lws_dll2_add_sorted
LWS_VISIBLE LWS_EXTERN void lws_dll2_add_sorted(lws_dll2_t *d, lws_dll2_owner_t *own, int(*compare)(const lws_dll2_t *d, const lws_dll2_t *i))
lws_dll2_owner_t
struct lws_dll2_owner lws_dll2_owner_t
lws_dll2_add_insert
LWS_VISIBLE LWS_EXTERN void lws_dll2_add_insert(struct lws_dll2 *d, struct lws_dll2 *prev)
_lws_dll2_search_sz_pl
LWS_VISIBLE LWS_EXTERN void * _lws_dll2_search_sz_pl(lws_dll2_owner_t *own, const char *name, size_t namelen, size_t dll2_ofs, size_t ptr_ofs)
lws_dll2_add_before
LWS_VISIBLE LWS_EXTERN void lws_dll2_add_before(struct lws_dll2 *d, struct lws_dll2 *after)
lws_dll2_foreach_cb_t
int(* lws_dll2_foreach_cb_t)(struct lws_dll2 *d, void *user)
Definition
lws-dll2.h:260
lws_dll2_is_detached
LWS_VISIBLE LWS_EXTERN int lws_dll2_is_detached(const struct lws_dll2 *d)
lws_dll2_remove
LWS_VISIBLE LWS_EXTERN void lws_dll2_remove(struct lws_dll2 *d)
lws_dll2_clear
LWS_VISIBLE LWS_EXTERN void lws_dll2_clear(struct lws_dll2 *d)
lws_dll2_foreach_safe
LWS_VISIBLE LWS_EXTERN int lws_dll2_foreach_safe(struct lws_dll2_owner *owner, void *user, lws_dll2_foreach_cb_t cb)
lws_dll2_add_head
LWS_VISIBLE LWS_EXTERN void lws_dll2_add_head(struct lws_dll2 *d, struct lws_dll2_owner *owner)
lws_dll2
Definition
lws-dll2.h:226
lws_dll2_owner
Definition
lws-dll2.h:232
uint32_t
unsigned int uint32_t
Definition
libwebsockets.h:697
LWS_INLINE
#define LWS_INLINE
Definition
libwebsockets.h:232
LWS_EXTERN
#define LWS_EXTERN
Definition
libwebsockets.h:296
LWS_VISIBLE
#define LWS_VISIBLE
Definition
libwebsockets.h:291
include
libwebsockets
lws-dll2.h
Generated on
for libwebsockets by
1.18.0