maph 1.0.0 High-Performance Memory-Mapped Key-Value Database with O(1) Lookups

Loading...
Searching...
No Matches
context.c
Go to the documentation of this file.
1/*
2 * Authored by Alex Hultman, 2018-2019.
3 * Intellectual property of third-party.
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "libusockets.h"
19#include "internal/internal.h"
20#include <stdlib.h>
21#include <string.h>
22
23 int default_is_low_prio_handler(struct us_socket_t *s) {
24 return 0;
25}
26
27/* Shared with SSL */
28
29 unsigned short us_socket_context_timestamp(int ssl, struct us_socket_context_t *context) {
30 return context->timestamp;
31}
32
33 void us_listen_socket_close(int ssl, struct us_listen_socket_t *ls) {
34 /* us_listen_socket_t extends us_socket_t so we close in similar ways */
35 if (!us_socket_is_closed(0, &ls->s)) {
36 us_internal_socket_context_unlink_listen_socket(ls->s.context, ls);
37 us_poll_stop((struct us_poll_t *) &ls->s, ls->s.context->loop);
38 bsd_close_socket(us_poll_fd((struct us_poll_t *) &ls->s));
39
40 /* Link this socket to the close-list and let it be deleted after this iteration */
41 ls->s.next = ls->s.context->loop->data.closed_head;
42 ls->s.context->loop->data.closed_head = &ls->s;
43
44 /* Any socket with prev = context is marked as closed */
45 ls->s.prev = (struct us_socket_t *) ls->s.context;
46 }
47
48 /* We cannot immediately free a listen socket as we can be inside an accept loop */
49}
50
51 void us_socket_context_close(int ssl, struct us_socket_context_t *context) {
52 /* Begin by closing all listen sockets */
53 struct us_listen_socket_t *ls = context->head_listen_sockets;
54 while (ls) {
55 struct us_listen_socket_t *nextLS = (struct us_listen_socket_t *) ls->s.next;
56 us_listen_socket_close(ssl, ls);
57 ls = nextLS;
58 }
59
60 /* Then close all regular sockets */
61 struct us_socket_t *s = context->head_sockets;
62 while (s) {
63 struct us_socket_t *nextS = s->next;
64 us_socket_close(ssl, s, 0, 0);
65 s = nextS;
66 }
67}
68
69 void us_internal_socket_context_unlink_listen_socket(struct us_socket_context_t *context, struct us_listen_socket_t *ls) {
70 /* We have to properly update the iterator used to sweep sockets for timeouts */
71 if (ls == (struct us_listen_socket_t *) context->iterator) {
72 context->iterator = ls->s.next;
73 }
74
75 if (ls->s.prev == ls->s.next) {
76 context->head_listen_sockets = 0;
77 } else {
78 if (ls->s.prev) {
79 ls->s.prev->next = ls->s.next;
80 } else {
81 context->head_listen_sockets = (struct us_listen_socket_t *) ls->s.next;
82 }
83 if (ls->s.next) {
84 ls->s.next->prev = ls->s.prev;
85 }
86 }
87}
88
89 void us_internal_socket_context_unlink_socket(struct us_socket_context_t *context, struct us_socket_t *s) {
90 /* We have to properly update the iterator used to sweep sockets for timeouts */
91 if (s == context->iterator) {
92 context->iterator = s->next;
93 }
94
95 if (s->prev == s->next) {
96 context->head_sockets = 0;
97 } else {
98 if (s->prev) {
99 s->prev->next = s->next;
100 } else {
101 context->head_sockets = s->next;
102 }
103 if (s->next) {
104 s->next->prev = s->prev;
105 }
106 }
107}
108
109/* We always add in the top, so we don't modify any s.next */
110 void us_internal_socket_context_link_listen_socket(struct us_socket_context_t *context, struct us_listen_socket_t *ls) {
111 ls->s.context = context;
112 ls->s.next = (struct us_socket_t *) context->head_listen_sockets;
113 ls->s.prev = 0;
114 if (context->head_listen_sockets) {
115 context->head_listen_sockets->s.prev = &ls->s;
116 }
117 context->head_listen_sockets = ls;
118}
119
120/* We always add in the top, so we don't modify any s.next */
121 void us_internal_socket_context_link_socket(struct us_socket_context_t *context, struct us_socket_t *s) {
122 s->context = context;
123 s->next = context->head_sockets;
124 s->prev = 0;
125 if (context->head_sockets) {
126 context->head_sockets->prev = s;
127 }
128 context->head_sockets = s;
129}
130
131 struct us_loop_t *us_socket_context_loop(int ssl, struct us_socket_context_t *context) {
132 return context->loop;
133}
134
135/* Not shared with SSL */
136
137/* Lookup userdata by server name pattern */
138 void *us_socket_context_find_server_name_userdata(int ssl, struct us_socket_context_t *context, const char *hostname_pattern) {
139#ifndef LIBUS_NO_SSL
140 if (ssl) {
141 return us_internal_ssl_socket_context_find_server_name_userdata((struct us_internal_ssl_socket_context_t *) context, hostname_pattern);
142 }
143#endif
144 return NULL;
145}
146
147/* Get userdata attached to this SNI-routed socket, or nullptr if default */
148 void *us_socket_server_name_userdata(int ssl, struct us_socket_t *s) {
149#ifndef LIBUS_NO_SSL
150 if (ssl) {
151 return us_internal_ssl_socket_get_sni_userdata((struct us_internal_ssl_socket_t *) s);
152 }
153#endif
154 return NULL;
155}
156
157/* Add SNI context */
158 void us_socket_context_add_server_name(int ssl, struct us_socket_context_t *context, const char *hostname_pattern, struct us_socket_context_options_t options, void *user) {
159#ifndef LIBUS_NO_SSL
160 if (ssl) {
161 us_internal_ssl_socket_context_add_server_name((struct us_internal_ssl_socket_context_t *) context, hostname_pattern, options, user);
162 }
163#endif
164}
165
166/* Remove SNI context */
167 void us_socket_context_remove_server_name(int ssl, struct us_socket_context_t *context, const char *hostname_pattern) {
168#ifndef LIBUS_NO_SSL
169 if (ssl) {
170 us_internal_ssl_socket_context_remove_server_name((struct us_internal_ssl_socket_context_t *) context, hostname_pattern);
171 }
172#endif
173}
174
175/* I don't like this one - maybe rename it to on_missing_server_name? */
176
177/* Called when SNI matching fails - not if a match could be made.
178 * You may modify the context by adding/removing names in this callback.
179 * If the correct name is added immediately in the callback, it will be used */
180 void us_socket_context_on_server_name(int ssl, struct us_socket_context_t *context, void (*cb)(struct us_socket_context_t *, const char *hostname)) {
181#ifndef LIBUS_NO_SSL
182 if (ssl) {
183 us_internal_ssl_socket_context_on_server_name((struct us_internal_ssl_socket_context_t *) context, (void (*)(struct us_internal_ssl_socket_context_t *, const char *hostname)) cb);
184 }
185#endif
186}
187
188/* Todo: get native context from SNI pattern */
189
190 void *us_socket_context_get_native_handle(int ssl, struct us_socket_context_t *context) {
191#ifndef LIBUS_NO_SSL
192 if (ssl) {
193 return us_internal_ssl_socket_context_get_native_handle((struct us_internal_ssl_socket_context_t *) context);
194 }
195#endif
196
197 /* There is no native handle for a non-SSL socket context */
198 return 0;
199}
200
201/* Options is currently only applicable for SSL - this will change with time (prefer_low_memory is one example) */
202 struct us_socket_context_t *us_create_socket_context(int ssl, struct us_loop_t *loop, int context_ext_size, struct us_socket_context_options_t options) {
203#ifndef LIBUS_NO_SSL
204 if (ssl) {
205 /* This function will call us, again, with SSL = false and a bigger ext_size */
206 return (struct us_socket_context_t *) us_internal_create_ssl_socket_context(loop, context_ext_size, options);
207 }
208#endif
209
210 /* This path is taken once either way - always BEFORE whatever SSL may do LATER.
211 * context_ext_size will however be modified larger in case of SSL, to hold SSL extensions */
212
213 struct us_socket_context_t *context = malloc(sizeof(struct us_socket_context_t) + context_ext_size);
214 context->loop = loop;
215 context->head_sockets = 0;
216 context->head_listen_sockets = 0;
217 context->iterator = 0;
218 context->next = 0;
219 context->is_low_prio = default_is_low_prio_handler;
220
221 /* Begin at 0 */
222 context->timestamp = 0;
223 context->long_timestamp = 0;
224 context->global_tick = 0;
225
226 us_internal_loop_link(loop, context);
227
228 /* If we are called from within SSL code, SSL code will make further changes to us */
229 return context;
230}
231
232 void us_socket_context_free(int ssl, struct us_socket_context_t *context) {
233#ifndef LIBUS_NO_SSL
234 if (ssl) {
235 /* This function will call us again with SSL=false */
236 us_internal_ssl_socket_context_free((struct us_internal_ssl_socket_context_t *) context);
237 return;
238 }
239#endif
240
241 /* This path is taken once either way - always AFTER whatever SSL may do BEFORE.
242 * This is the opposite order compared to when creating the context - SSL code is cleaning up before non-SSL */
243
244 us_internal_loop_unlink(context->loop, context);
245 free(context);
246}
247
248 struct us_listen_socket_t *us_socket_context_listen(int ssl, struct us_socket_context_t *context, const char *host, int port, int options, int socket_ext_size) {
249#ifndef LIBUS_NO_SSL
250 if (ssl) {
251 return us_internal_ssl_socket_context_listen((struct us_internal_ssl_socket_context_t *) context, host, port, options, socket_ext_size);
252 }
253#endif
254
255 LIBUS_SOCKET_DESCRIPTOR listen_socket_fd = bsd_create_listen_socket(host, port, options);
256
257 if (listen_socket_fd == LIBUS_SOCKET_ERROR) {
258 return 0;
259 }
260
261 struct us_poll_t *p = us_create_poll(context->loop, 0, sizeof(struct us_listen_socket_t));
262 us_poll_init(p, listen_socket_fd, POLL_TYPE_SEMI_SOCKET);
263 us_poll_start(p, context->loop, LIBUS_SOCKET_READABLE);
264
265 struct us_listen_socket_t *ls = (struct us_listen_socket_t *) p;
266
267 ls->s.context = context;
268 ls->s.timeout = 255;
269 ls->s.long_timeout = 255;
270 ls->s.low_prio_state = 0;
271 ls->s.next = 0;
272 us_internal_socket_context_link_listen_socket(context, ls);
273
274 ls->socket_ext_size = socket_ext_size;
275
276 return ls;
277}
278
279 struct us_listen_socket_t *us_socket_context_listen_unix(int ssl, struct us_socket_context_t *context, const char *path, int options, int socket_ext_size) {
280#ifndef LIBUS_NO_SSL
281 if (ssl) {
282 return us_internal_ssl_socket_context_listen_unix((struct us_internal_ssl_socket_context_t *) context, path, options, socket_ext_size);
283 }
284#endif
285
286 LIBUS_SOCKET_DESCRIPTOR listen_socket_fd = bsd_create_listen_socket_unix(path, options);
287
288 if (listen_socket_fd == LIBUS_SOCKET_ERROR) {
289 return 0;
290 }
291
292 struct us_poll_t *p = us_create_poll(context->loop, 0, sizeof(struct us_listen_socket_t));
293 us_poll_init(p, listen_socket_fd, POLL_TYPE_SEMI_SOCKET);
294 us_poll_start(p, context->loop, LIBUS_SOCKET_READABLE);
295
296 struct us_listen_socket_t *ls = (struct us_listen_socket_t *) p;
297
298 ls->s.context = context;
299 ls->s.timeout = 255;
300 ls->s.long_timeout = 255;
301 ls->s.low_prio_state = 0;
302 ls->s.next = 0;
303 us_internal_socket_context_link_listen_socket(context, ls);
304
305 ls->socket_ext_size = socket_ext_size;
306
307 return ls;
308}
309
310 struct us_socket_t *us_socket_context_connect(int ssl, struct us_socket_context_t *context, const char *host, int port, const char *source_host, int options, int socket_ext_size) {
311#ifndef LIBUS_NO_SSL
312 if (ssl) {
313 return (struct us_socket_t *) us_internal_ssl_socket_context_connect((struct us_internal_ssl_socket_context_t *) context, host, port, source_host, options, socket_ext_size);
314 }
315#endif
316
317 LIBUS_SOCKET_DESCRIPTOR connect_socket_fd = bsd_create_connect_socket(host, port, source_host, options);
318 if (connect_socket_fd == LIBUS_SOCKET_ERROR) {
319 return 0;
320 }
321
322 /* Connect sockets are semi-sockets just like listen sockets */
323 struct us_poll_t *p = us_create_poll(context->loop, 0, sizeof(struct us_socket_t) + socket_ext_size);
324 us_poll_init(p, connect_socket_fd, POLL_TYPE_SEMI_SOCKET);
325 us_poll_start(p, context->loop, LIBUS_SOCKET_WRITABLE);
326
327 struct us_socket_t *connect_socket = (struct us_socket_t *) p;
328
329 /* Link it into context so that timeout fires properly */
330 connect_socket->context = context;
331 connect_socket->timeout = 255;
332 connect_socket->long_timeout = 255;
333 connect_socket->low_prio_state = 0;
334 us_internal_socket_context_link_socket(context, connect_socket);
335
336 return connect_socket;
337}
338
339 struct us_socket_t *us_socket_context_connect_unix(int ssl, struct us_socket_context_t *context, const char *server_path, int options, int socket_ext_size) {
340#ifndef LIBUS_NO_SSL
341 if (ssl) {
342 return (struct us_socket_t *) us_internal_ssl_socket_context_connect_unix((struct us_internal_ssl_socket_context_t *) context, server_path, options, socket_ext_size);
343 }
344#endif
345
346 LIBUS_SOCKET_DESCRIPTOR connect_socket_fd = bsd_create_connect_socket_unix(server_path, options);
347 if (connect_socket_fd == LIBUS_SOCKET_ERROR) {
348 return 0;
349 }
350
351 /* Connect sockets are semi-sockets just like listen sockets */
352 struct us_poll_t *p = us_create_poll(context->loop, 0, sizeof(struct us_socket_t) + socket_ext_size);
353 us_poll_init(p, connect_socket_fd, POLL_TYPE_SEMI_SOCKET);
354 us_poll_start(p, context->loop, LIBUS_SOCKET_WRITABLE);
355
356 struct us_socket_t *connect_socket = (struct us_socket_t *) p;
357
358 /* Link it into context so that timeout fires properly */
359 connect_socket->context = context;
360 connect_socket->timeout = 255;
361 connect_socket->long_timeout = 255;
362 connect_socket->low_prio_state = 0;
363 us_internal_socket_context_link_socket(context, connect_socket);
364
365 return connect_socket;
366}
367
368 struct us_socket_context_t *us_create_child_socket_context(int ssl, struct us_socket_context_t *context, int context_ext_size) {
369#ifndef LIBUS_NO_SSL
370 if (ssl) {
371 return (struct us_socket_context_t *) us_internal_create_child_ssl_socket_context((struct us_internal_ssl_socket_context_t *) context, context_ext_size);
372 }
373#endif
374
375 /* For TCP we simply create a new context as nothing is shared */
376 struct us_socket_context_options_t options = {0};
377 return us_create_socket_context(ssl, context->loop, context_ext_size, options);
378}
379
380/* Note: This will set timeout to 0 */
381 struct us_socket_t *us_socket_context_adopt_socket(int ssl, struct us_socket_context_t *context, struct us_socket_t *s, int ext_size) {
382#ifndef LIBUS_NO_SSL
383 if (ssl) {
384 return (struct us_socket_t *) us_internal_ssl_socket_context_adopt_socket((struct us_internal_ssl_socket_context_t *) context, (struct us_internal_ssl_socket_t *) s, ext_size);
385 }
386#endif
387
388 /* Cannot adopt a closed socket */
389 if (us_socket_is_closed(ssl, s)) {
390 return s;
391 }
392
393 if (s->low_prio_state != 1) {
394 /* This properly updates the iterator if in on_timeout */
395 us_internal_socket_context_unlink_socket(s->context, s);
396 }
397
398 struct us_socket_t *new_s = (struct us_socket_t *) us_poll_resize(&s->p, s->context->loop, sizeof(struct us_socket_t) + ext_size);
399 new_s->timeout = 255;
400 new_s->long_timeout = 255;
401
402 if (new_s->low_prio_state == 1) {
403 /* update pointers in low-priority queue */
404 if (!new_s->prev) new_s->context->loop->data.low_prio_head = new_s;
405 else new_s->prev->next = new_s;
406
407 if (new_s->next) new_s->next->prev = new_s;
408 } else {
409 us_internal_socket_context_link_socket(context, new_s);
410 }
411
412 return new_s;
413}
414
415 void us_socket_context_on_open(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_open)(struct us_socket_t *s, int is_client, char *ip, int ip_length)) {
416#ifndef LIBUS_NO_SSL
417 if (ssl) {
418 us_internal_ssl_socket_context_on_open((struct us_internal_ssl_socket_context_t *) context, (struct us_internal_ssl_socket_t * (*)(struct us_internal_ssl_socket_t *, int, char *, int)) on_open);
419 return;
420 }
421#endif
422
423 context->on_open = on_open;
424}
425
426 void us_socket_context_on_close(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_close)(struct us_socket_t *s, int code, void *reason)) {
427#ifndef LIBUS_NO_SSL
428 if (ssl) {
429 us_internal_ssl_socket_context_on_close((struct us_internal_ssl_socket_context_t *) context, (struct us_internal_ssl_socket_t * (*)(struct us_internal_ssl_socket_t *, int code, void *reason)) on_close);
430 return;
431 }
432#endif
433
434 context->on_close = on_close;
435}
436
437 void us_socket_context_on_data(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_data)(struct us_socket_t *s, char *data, int length)) {
438#ifndef LIBUS_NO_SSL
439 if (ssl) {
440 us_internal_ssl_socket_context_on_data((struct us_internal_ssl_socket_context_t *) context, (struct us_internal_ssl_socket_t * (*)(struct us_internal_ssl_socket_t *, char *, int)) on_data);
441 return;
442 }
443#endif
444
445 context->on_data = on_data;
446}
447
448 void us_socket_context_on_writable(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_writable)(struct us_socket_t *s)) {
449#ifndef LIBUS_NO_SSL
450 if (ssl) {
451 us_internal_ssl_socket_context_on_writable((struct us_internal_ssl_socket_context_t *) context, (struct us_internal_ssl_socket_t * (*)(struct us_internal_ssl_socket_t *)) on_writable);
452 return;
453 }
454#endif
455
456 context->on_writable = on_writable;
457}
458
459 void us_socket_context_on_long_timeout(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_long_timeout)(struct us_socket_t *)) {
460#ifndef LIBUS_NO_SSL
461 if (ssl) {
462 us_internal_ssl_socket_context_on_long_timeout((struct us_internal_ssl_socket_context_t *) context, (struct us_internal_ssl_socket_t * (*)(struct us_internal_ssl_socket_t *)) on_long_timeout);
463 return;
464 }
465#endif
466
467 context->on_socket_long_timeout = on_long_timeout;
468}
469
470 void us_socket_context_on_timeout(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_timeout)(struct us_socket_t *)) {
471#ifndef LIBUS_NO_SSL
472 if (ssl) {
473 us_internal_ssl_socket_context_on_timeout((struct us_internal_ssl_socket_context_t *) context, (struct us_internal_ssl_socket_t * (*)(struct us_internal_ssl_socket_t *)) on_timeout);
474 return;
475 }
476#endif
477
478 context->on_socket_timeout = on_timeout;
479}
480
481 void us_socket_context_on_end(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_end)(struct us_socket_t *)) {
482#ifndef LIBUS_NO_SSL
483 if (ssl) {
484 us_internal_ssl_socket_context_on_end((struct us_internal_ssl_socket_context_t *) context, (struct us_internal_ssl_socket_t * (*)(struct us_internal_ssl_socket_t *)) on_end);
485 return;
486 }
487#endif
488
489 context->on_end = on_end;
490}
491
492 void us_socket_context_on_connect_error(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_connect_error)(struct us_socket_t *s, int code)) {
493#ifndef LIBUS_NO_SSL
494 if (ssl) {
495 us_internal_ssl_socket_context_on_connect_error((struct us_internal_ssl_socket_context_t *) context, (struct us_internal_ssl_socket_t * (*)(struct us_internal_ssl_socket_t *, int)) on_connect_error);
496 return;
497 }
498#endif
499
500 context->on_connect_error = on_connect_error;
501}
502
503 void *us_socket_context_ext(int ssl, struct us_socket_context_t *context) {
504#ifndef LIBUS_NO_SSL
505 if (ssl) {
506 return us_internal_ssl_socket_context_ext((struct us_internal_ssl_socket_context_t *) context);
507 }
508#endif
509
510 return context + 1;
511}
LIBUS_SOCKET_WRITABLE
#define LIBUS_SOCKET_WRITABLE
Definition asio.h:24
LIBUS_SOCKET_READABLE
#define LIBUS_SOCKET_READABLE
Definition asio.h:23
bsd_create_connect_socket_unix
int bsd_create_connect_socket_unix(const char *server_path, int options)
Definition bsd.c:706
bsd_create_listen_socket
int bsd_create_listen_socket(const char *host, int port, int options)
Definition bsd.c:432
bsd_close_socket
void bsd_close_socket(int fd)
Definition bsd.c:302
bsd_create_connect_socket
int bsd_create_connect_socket(const char *host, int port, const char *source_host, int options)
Definition bsd.c:668
bsd_create_listen_socket_unix
int bsd_create_listen_socket_unix(const char *path, int options)
Definition bsd.c:514
LIBUS_SOCKET_ERROR
#define LIBUS_SOCKET_ERROR
Definition bsd.h:44
us_internal_socket_context_link_listen_socket
void us_internal_socket_context_link_listen_socket(struct us_socket_context_t *context, struct us_listen_socket_t *ls)
Definition context.c:110
us_socket_context_listen
struct us_listen_socket_t * us_socket_context_listen(int ssl, struct us_socket_context_t *context, const char *host, int port, int options, int socket_ext_size)
Definition context.c:248
us_socket_context_remove_server_name
void us_socket_context_remove_server_name(int ssl, struct us_socket_context_t *context, const char *hostname_pattern)
Definition context.c:167
us_socket_context_listen_unix
struct us_listen_socket_t * us_socket_context_listen_unix(int ssl, struct us_socket_context_t *context, const char *path, int options, int socket_ext_size)
Definition context.c:279
us_socket_context_on_server_name
void us_socket_context_on_server_name(int ssl, struct us_socket_context_t *context, void(*cb)(struct us_socket_context_t *, const char *hostname))
Definition context.c:180
us_socket_context_connect
struct us_socket_t * us_socket_context_connect(int ssl, struct us_socket_context_t *context, const char *host, int port, const char *source_host, int options, int socket_ext_size)
Definition context.c:310
us_socket_context_close
void us_socket_context_close(int ssl, struct us_socket_context_t *context)
Definition context.c:51
us_socket_context_on_data
void us_socket_context_on_data(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_data)(struct us_socket_t *s, char *data, int length))
Definition context.c:437
us_socket_context_timestamp
unsigned short us_socket_context_timestamp(int ssl, struct us_socket_context_t *context)
Definition context.c:29
us_socket_server_name_userdata
void * us_socket_server_name_userdata(int ssl, struct us_socket_t *s)
Definition context.c:148
us_create_child_socket_context
struct us_socket_context_t * us_create_child_socket_context(int ssl, struct us_socket_context_t *context, int context_ext_size)
Definition context.c:368
us_socket_context_on_writable
void us_socket_context_on_writable(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_writable)(struct us_socket_t *s))
Definition context.c:448
us_socket_context_on_timeout
void us_socket_context_on_timeout(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_timeout)(struct us_socket_t *))
Definition context.c:470
us_socket_context_on_long_timeout
void us_socket_context_on_long_timeout(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_long_timeout)(struct us_socket_t *))
Definition context.c:459
default_is_low_prio_handler
int default_is_low_prio_handler(struct us_socket_t *s)
Definition context.c:23
us_socket_context_loop
struct us_loop_t * us_socket_context_loop(int ssl, struct us_socket_context_t *context)
Definition context.c:131
us_socket_context_add_server_name
void us_socket_context_add_server_name(int ssl, struct us_socket_context_t *context, const char *hostname_pattern, struct us_socket_context_options_t options, void *user)
Definition context.c:158
us_listen_socket_close
void us_listen_socket_close(int ssl, struct us_listen_socket_t *ls)
Definition context.c:33
us_internal_socket_context_unlink_socket
void us_internal_socket_context_unlink_socket(struct us_socket_context_t *context, struct us_socket_t *s)
Definition context.c:89
us_internal_socket_context_unlink_listen_socket
void us_internal_socket_context_unlink_listen_socket(struct us_socket_context_t *context, struct us_listen_socket_t *ls)
Definition context.c:69
us_socket_context_adopt_socket
struct us_socket_t * us_socket_context_adopt_socket(int ssl, struct us_socket_context_t *context, struct us_socket_t *s, int ext_size)
Definition context.c:381
us_socket_context_on_close
void us_socket_context_on_close(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_close)(struct us_socket_t *s, int code, void *reason))
Definition context.c:426
us_socket_context_get_native_handle
void * us_socket_context_get_native_handle(int ssl, struct us_socket_context_t *context)
Definition context.c:190
us_socket_context_connect_unix
struct us_socket_t * us_socket_context_connect_unix(int ssl, struct us_socket_context_t *context, const char *server_path, int options, int socket_ext_size)
Definition context.c:339
us_socket_context_ext
void * us_socket_context_ext(int ssl, struct us_socket_context_t *context)
Definition context.c:503
us_create_socket_context
struct us_socket_context_t * us_create_socket_context(int ssl, struct us_loop_t *loop, int context_ext_size, struct us_socket_context_options_t options)
Definition context.c:202
us_socket_context_on_connect_error
void us_socket_context_on_connect_error(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_connect_error)(struct us_socket_t *s, int code))
Definition context.c:492
us_socket_context_find_server_name_userdata
void * us_socket_context_find_server_name_userdata(int ssl, struct us_socket_context_t *context, const char *hostname_pattern)
Definition context.c:138
us_internal_socket_context_link_socket
void us_internal_socket_context_link_socket(struct us_socket_context_t *context, struct us_socket_t *s)
Definition context.c:121
us_socket_context_on_open
void us_socket_context_on_open(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_open)(struct us_socket_t *s, int is_client, char *ip, int ip_length))
Definition context.c:415
us_socket_context_on_end
void us_socket_context_on_end(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_end)(struct us_socket_t *))
Definition context.c:481
us_socket_context_free
void us_socket_context_free(int ssl, struct us_socket_context_t *context)
Definition context.c:232
internal.h
us_internal_ssl_socket_context_free
void us_internal_ssl_socket_context_free(struct us_internal_ssl_socket_context_t *context)
us_internal_loop_unlink
void us_internal_loop_unlink(struct us_loop_t *loop, struct us_socket_context_t *context)
Definition loop.c:68
us_listen_socket_t::s
struct us_socket_t s
Definition internal.h:109
us_internal_ssl_socket_context_on_connect_error
void us_internal_ssl_socket_context_on_connect_error(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *(*on_connect_error)(struct us_internal_ssl_socket_t *s, int code))
us_socket_t::p
struct us_poll_t p
Definition internal.h:90
us_internal_ssl_socket_context_adopt_socket
struct us_internal_ssl_socket_t * us_internal_ssl_socket_context_adopt_socket(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *s, int ext_size)
us_internal_ssl_socket_context_on_close
void us_internal_ssl_socket_context_on_close(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *(*on_close)(struct us_internal_ssl_socket_t *s, int code, void *reason))
us_socket_t::long_timeout
unsigned char long_timeout
Definition internal.h:92
us_socket_t::next
struct us_socket_t * next
Definition internal.h:95
us_internal_ssl_socket_context_connect_unix
struct us_internal_ssl_socket_t * us_internal_ssl_socket_context_connect_unix(struct us_internal_ssl_socket_context_t *context, const char *server_path, int options, int socket_ext_size)
us_internal_ssl_socket_context_remove_server_name
void us_internal_ssl_socket_context_remove_server_name(struct us_internal_ssl_socket_context_t *context, const char *hostname_pattern)
us_internal_ssl_socket_context_on_timeout
void us_internal_ssl_socket_context_on_timeout(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *(*on_timeout)(struct us_internal_ssl_socket_t *s))
us_internal_create_child_ssl_socket_context
struct us_internal_ssl_socket_context_t * us_internal_create_child_ssl_socket_context(struct us_internal_ssl_socket_context_t *context, int context_ext_size)
us_internal_ssl_socket_context_listen
struct us_listen_socket_t * us_internal_ssl_socket_context_listen(struct us_internal_ssl_socket_context_t *context, const char *host, int port, int options, int socket_ext_size)
us_internal_create_ssl_socket_context
struct us_internal_ssl_socket_context_t * us_internal_create_ssl_socket_context(struct us_loop_t *loop, int context_ext_size, struct us_socket_context_options_t options)
us_internal_ssl_socket_context_on_data
void us_internal_ssl_socket_context_on_data(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *(*on_data)(struct us_internal_ssl_socket_t *s, char *data, int length))
us_internal_ssl_socket_context_add_server_name
void us_internal_ssl_socket_context_add_server_name(struct us_internal_ssl_socket_context_t *context, const char *hostname_pattern, struct us_socket_context_options_t options, void *user)
us_internal_ssl_socket_context_listen_unix
struct us_listen_socket_t * us_internal_ssl_socket_context_listen_unix(struct us_internal_ssl_socket_context_t *context, const char *path, int options, int socket_ext_size)
us_internal_ssl_socket_get_sni_userdata
void * us_internal_ssl_socket_get_sni_userdata(struct us_internal_ssl_socket_t *s)
us_internal_ssl_socket_context_on_long_timeout
void us_internal_ssl_socket_context_on_long_timeout(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *(*on_timeout)(struct us_internal_ssl_socket_t *s))
us_socket_t::timeout
unsigned char timeout
Definition internal.h:91
us_socket_t::prev
struct us_socket_t * prev
Definition internal.h:95
us_internal_loop_link
void us_internal_loop_link(struct us_loop_t *loop, struct us_socket_context_t *context)
Definition loop.c:57
us_socket_t::low_prio_state
unsigned short low_prio_state
Definition internal.h:93
us_socket_t::context
struct us_socket_context_t * context
Definition internal.h:94
us_internal_ssl_socket_context_ext
void * us_internal_ssl_socket_context_ext(struct us_internal_ssl_socket_context_t *s)
us_internal_ssl_socket_context_find_server_name_userdata
void * us_internal_ssl_socket_context_find_server_name_userdata(struct us_internal_ssl_socket_context_t *context, const char *hostname_pattern)
us_listen_socket_t::socket_ext_size
unsigned int socket_ext_size
Definition internal.h:110
us_internal_ssl_socket_context_on_writable
void us_internal_ssl_socket_context_on_writable(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *(*on_writable)(struct us_internal_ssl_socket_t *s))
POLL_TYPE_SEMI_SOCKET
@ POLL_TYPE_SEMI_SOCKET
Definition internal.h:49
us_internal_ssl_socket_context_on_server_name
void us_internal_ssl_socket_context_on_server_name(struct us_internal_ssl_socket_context_t *context, void(*cb)(struct us_internal_ssl_socket_context_t *, const char *))
us_internal_ssl_socket_context_get_native_handle
void * us_internal_ssl_socket_context_get_native_handle(struct us_internal_ssl_socket_context_t *context)
us_internal_ssl_socket_context_on_end
void us_internal_ssl_socket_context_on_end(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *(*on_end)(struct us_internal_ssl_socket_t *s))
us_internal_ssl_socket_context_on_open
void us_internal_ssl_socket_context_on_open(struct us_internal_ssl_socket_context_t *context, struct us_internal_ssl_socket_t *(*on_open)(struct us_internal_ssl_socket_t *s, int is_client, char *ip, int ip_length))
us_internal_ssl_socket_context_connect
struct us_internal_ssl_socket_t * us_internal_ssl_socket_context_connect(struct us_internal_ssl_socket_context_t *context, const char *host, int port, const char *source_host, int options, int socket_ext_size)
us_listen_socket_t
Definition internal.h:108
us_socket_t
Definition internal.h:89
libusockets.h
us_poll_init
void us_poll_init(struct us_poll_t *p, int fd, int poll_type)
LIBUS_SOCKET_DESCRIPTOR
#define LIBUS_SOCKET_DESCRIPTOR
Definition libusockets.h:38
us_create_poll
struct us_poll_t * us_create_poll(struct us_loop_t *loop, int fallthrough, unsigned int ext_size)
us_poll_resize
struct us_poll_t * us_poll_resize(struct us_poll_t *p, struct us_loop_t *loop, unsigned int ext_size)
us_poll_fd
int us_poll_fd(struct us_poll_t *p)
us_poll_stop
void us_poll_stop(struct us_poll_t *p, struct us_loop_t *loop)
us_socket_close
struct us_socket_t * us_socket_close(int ssl, struct us_socket_t *s, int code, void *reason)
Definition socket.c:105
us_poll_start
void us_poll_start(struct us_poll_t *p, struct us_loop_t *loop, int events)
us_socket_is_closed
int us_socket_is_closed(int ssl, struct us_socket_t *s)
Definition socket.c:76
us_socket_context_options_t
Definition libusockets.h:124
us_loop_t::data
struct us_internal_loop_data_t data
Definition asio.h:27
us_poll_t
Definition asio.h:37
us_loop_t
Definition asio.h:26
us_internal_loop_data_t::low_prio_head
struct us_socket_t * low_prio_head
Definition loop_data.h:32
us_internal_loop_data_t::closed_head
struct us_socket_t * closed_head
Definition loop_data.h:31
us_socket_context_t
Definition internal.h:117
us_socket_context_t::on_end
struct us_socket_t *(* on_end)(struct us_socket_t *)
Definition internal.h:134
us_socket_context_t::head_sockets
struct us_socket_t * head_sockets
Definition internal.h:122
us_socket_context_t::long_timestamp
unsigned char long_timestamp
Definition internal.h:121
us_socket_context_t::on_close
struct us_socket_t *(* on_close)(struct us_socket_t *, int code, void *reason)
Definition internal.h:130
us_socket_context_t::timestamp
unsigned char timestamp
Definition internal.h:120
us_socket_context_t::is_low_prio
int(* is_low_prio)(struct us_socket_t *)
Definition internal.h:136
us_socket_context_t::loop
struct us_loop_t * loop
Definition internal.h:118
us_socket_context_t::on_data
struct us_socket_t *(* on_data)(struct us_socket_t *, char *data, int length)
Definition internal.h:128
us_socket_context_t::head_listen_sockets
struct us_listen_socket_t * head_listen_sockets
Definition internal.h:123
us_socket_context_t::on_socket_timeout
struct us_socket_t *(* on_socket_timeout)(struct us_socket_t *)
Definition internal.h:132
us_socket_context_t::on_socket_long_timeout
struct us_socket_t *(* on_socket_long_timeout)(struct us_socket_t *)
Definition internal.h:133
us_socket_context_t::iterator
struct us_socket_t * iterator
Definition internal.h:124
us_socket_context_t::on_writable
struct us_socket_t *(* on_writable)(struct us_socket_t *)
Definition internal.h:129
us_socket_context_t::on_open
struct us_socket_t *(* on_open)(struct us_socket_t *, int is_client, char *ip, int ip_length)
Definition internal.h:127
us_socket_context_t::on_connect_error
struct us_socket_t *(* on_connect_error)(struct us_socket_t *, int code)
Definition internal.h:135
us_socket_context_t::next
struct us_socket_context_t * next
Definition internal.h:125
us_socket_context_t::global_tick
uint32_t global_tick
Definition internal.h:119