1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

vhost: allow user pointer to be attached at creation time

https://github.com/warmcat/libwebsockets/issues/1008
This commit is contained in:
Andy Green 2017-08-29 15:37:16 +08:00
parent f994a4f728
commit d6e8459c07
4 changed files with 27 additions and 2 deletions

View file

@ -482,6 +482,7 @@ lws_create_vhost(struct lws_context *context,
vh->options = info->options;
vh->pvo = info->pvo;
vh->headers = info->headers;
vh->user = info->user;
vh->ssl_info_event_mask = info->ssl_info_event_mask;
if (info->keepalive_timeout)
vh->keepalive_timeout = info->keepalive_timeout;

View file

@ -1011,6 +1011,12 @@ bail:
}
LWS_EXTERN void *
lws_vhost_user(struct lws_vhost *vhost)
{
return vhost->user;
}
LWS_EXTERN void *
lws_context_user(struct lws_context *context)
{

View file

@ -1935,8 +1935,14 @@ struct lws_context_creation_info {
unsigned int options;
/**< VHOST + CONTEXT: 0, or LWS_SERVER_OPTION_... bitfields */
void *user;
/**< CONTEXT: optional user pointer that can be recovered via the context
* pointer using lws_context_user */
/**< VHOST + CONTEXT: optional user pointer that will be associated
* with the context when creating the context (and can be retrieved by
* lws_context_user(context), or with the vhost when creating the vhost
* (and can be retrieved by lws_vhost_user(vhost)). You will need to
* use LWS_SERVER_OPTION_EXPLICIT_VHOSTS and create the vhost separately
* if you care about giving the context and vhost different user pointer
* values.
*/
int ka_time;
/**< CONTEXT: 0 for no TCP keepalive, otherwise apply this keepalive
* timeout to all libwebsocket sockets, client or server */
@ -2349,6 +2355,17 @@ LWS_VISIBLE LWS_EXTERN int
lws_json_dump_context(const struct lws_context *context, char *buf, int len,
int hide_vhosts);
/**
* lws_vhost_user() - get the user data associated with the vhost
* \param vhost: Websocket vhost
*
* This returns the optional user pointer that can be attached to
* a vhost when it was created. Lws never dereferences this pointer, it only
* sets it when the vhost is created, and returns it using this api.
*/
LWS_VISIBLE LWS_EXTERN void *
lws_vhost_user(struct lws_vhost *vhost);
/**
* lws_context_user() - get the user data associated with the context
* \param context: Websocket context

View file

@ -881,6 +881,7 @@ struct lws_vhost {
#ifndef LWS_NO_EXTENSIONS
const struct lws_extension *extensions;
#endif
void *user;
int listen_port;
unsigned int http_proxy_port;