|
20 | 20 | #include <stdlib.h> |
21 | 21 | #include <string.h> |
22 | 22 |
|
23 | | -int default_is_low_prio_handler(struct us_socket_t *s) { |
24 | | - return 0; |
25 | | -} |
| 23 | +int default_is_low_prio_handler(struct us_socket_t *s); |
26 | 24 |
|
27 | 25 | /* Shared with SSL */ |
28 | 26 |
|
29 | | -unsigned short us_socket_context_timestamp(int ssl, struct us_socket_context_t *context) { |
30 | | - return context->timestamp; |
31 | | -} |
32 | | - |
33 | 27 | void us_listen_socket_close(int ssl, struct us_listen_socket_t *ls) { |
34 | 28 | /* us_listen_socket_t extends us_socket_t so we close in similar ways */ |
35 | 29 | if (!us_socket_is_closed(0, &ls->s)) { |
@@ -128,10 +122,6 @@ void us_internal_socket_context_link_socket(struct us_socket_context_t *context, |
128 | 122 | context->head_sockets = s; |
129 | 123 | } |
130 | 124 |
|
131 | | -struct us_loop_t *us_socket_context_loop(int ssl, struct us_socket_context_t *context) { |
132 | | - return context->loop; |
133 | | -} |
134 | | - |
135 | 125 | /* Not shared with SSL */ |
136 | 126 |
|
137 | 127 | /* Lookup userdata by server name pattern */ |
@@ -198,53 +188,6 @@ void *us_socket_context_get_native_handle(int ssl, struct us_socket_context_t *c |
198 | 188 | return 0; |
199 | 189 | } |
200 | 190 |
|
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 | 191 | 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 | 192 | #ifndef LIBUS_NO_SSL |
250 | 193 | if (ssl) { |
@@ -412,94 +355,6 @@ struct us_socket_t *us_socket_context_adopt_socket(int ssl, struct us_socket_con |
412 | 355 | return new_s; |
413 | 356 | } |
414 | 357 |
|
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 | 358 | void *us_socket_context_ext(int ssl, struct us_socket_context_t *context) { |
504 | 359 | #ifndef LIBUS_NO_SSL |
505 | 360 | if (ssl) { |
|
0 commit comments