context: external_baggage_free_on_destroy
This adds a context creation-time member that points to something that should be freed when the context is destroyed. It's in preparation for context deprecation, when a context might be destroyed asynchronously... a related external with the lifetime of thee context should also be freed at that time. Adapt lwsws to use it with the context "strings" (also used for aligned structs created by the config) allocation.
This commit is contained in:
parent
ee94621b40
commit
69c88d9f0c
4 changed files with 15 additions and 1 deletions
|
@ -606,6 +606,9 @@ lws_create_context(struct lws_context_creation_info *info)
|
|||
context->pt_serv_buf_size = 4096;
|
||||
|
||||
context->reject_service_keywords = info->reject_service_keywords;
|
||||
if (info->external_baggage_free_on_destroy)
|
||||
context->external_baggage_free_on_destroy =
|
||||
info->external_baggage_free_on_destroy;
|
||||
|
||||
context->time_up = time(NULL);
|
||||
#ifndef LWS_NO_DAEMONIZE
|
||||
|
@ -960,5 +963,8 @@ lws_context_destroy(struct lws_context *context)
|
|||
|
||||
lws_plat_context_late_destroy(context);
|
||||
|
||||
if (context->external_baggage_free_on_destroy)
|
||||
free(context->external_baggage_free_on_destroy);
|
||||
|
||||
lws_free(context);
|
||||
}
|
||||
|
|
|
@ -1715,6 +1715,13 @@ struct lws_context_creation_info {
|
|||
*
|
||||
* Eg, "badrobot" "404 Not Found"
|
||||
*/
|
||||
void *external_baggage_free_on_destroy;
|
||||
/**< CONTEXT: NULL, or pointer to something externally malloc'd, that
|
||||
* should be freed when the context is destroyed. This allows you to
|
||||
* automatically sync the freeing action to the context destruction
|
||||
* action, so there is no need for an external free() if the context
|
||||
* succeeded to create.
|
||||
*/
|
||||
|
||||
/* Add new things just above here ---^
|
||||
* This is part of the ABI, don't needlessly break compatibility
|
||||
|
|
|
@ -833,6 +833,7 @@ struct lws_context {
|
|||
#endif
|
||||
struct lws_vhost *vhost_list;
|
||||
struct lws_plugin *plugin_list;
|
||||
void *external_baggage_free_on_destroy;
|
||||
const struct lws_token_limits *token_limits;
|
||||
void *user_space;
|
||||
const char *server_string;
|
||||
|
|
|
@ -161,6 +161,7 @@ int main(int argc, char **argv)
|
|||
|
||||
memset(&info, 0, sizeof(info));
|
||||
|
||||
info.external_baggage_free_on_destroy = config_strings;
|
||||
info.max_http_header_pool = 16;
|
||||
info.options = opts | LWS_SERVER_OPTION_VALIDATE_UTF8 |
|
||||
LWS_SERVER_OPTION_EXPLICIT_VHOSTS |
|
||||
|
@ -200,7 +201,6 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
lws_context_destroy(context);
|
||||
free(config_strings);
|
||||
|
||||
fprintf(stderr, "lwsws exited cleanly\n");
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue