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

wsi: opaque_user_data and accessors

Under some circumstances it's useful to tag a wsi with user
data, while still having an lws-allocated and destroyed pss.
This commit is contained in:
Andy Green 2018-12-01 06:35:20 +08:00
parent 6830f2d296
commit 43cf8bb391
7 changed files with 30 additions and 0 deletions

View file

@ -119,6 +119,11 @@ struct lws_client_connect_info {
* tokens
*/
void *opaque_user_data;
/**< This data has no meaning to lws but is applied to the client wsi
* and can be retrieved by user code with lws_get_opaque_user_data()
*/
/* Add new things just above here ---^
* This is part of the ABI, don't needlessly break compatibility
*

View file

@ -545,6 +545,12 @@ lws_get_opaque_parent_data(const struct lws *wsi);
LWS_VISIBLE LWS_EXTERN void
lws_set_opaque_parent_data(struct lws *wsi, void *data);
LWS_VISIBLE LWS_EXTERN void *
lws_get_opaque_user_data(const struct lws *wsi);
LWS_VISIBLE LWS_EXTERN void
lws_set_opaque_user_data(struct lws *wsi, void *data);
LWS_VISIBLE LWS_EXTERN int
lws_get_child_pending_on_writable(const struct lws *wsi);

View file

@ -189,6 +189,7 @@ lws_client_connect_via_info(const struct lws_client_connect_info *i)
wsi->stash->address = lws_strdup(i->address);
wsi->stash->path = lws_strdup(i->path);
wsi->stash->host = lws_strdup(i->host);
wsi->stash->opaque_user_data = i->opaque_user_data;
if (!wsi->stash->address || !wsi->stash->path || !wsi->stash->host)
goto bail1;

View file

@ -2367,6 +2367,18 @@ lws_set_opaque_parent_data(struct lws *wsi, void *data)
wsi->opaque_parent_data = data;
}
LWS_VISIBLE LWS_EXTERN void *
lws_get_opaque_user_data(const struct lws *wsi)
{
return wsi->opaque_user_data;
}
LWS_VISIBLE LWS_EXTERN void
lws_set_opaque_user_data(struct lws *wsi, void *data)
{
wsi->opaque_user_data = data;
}
LWS_VISIBLE LWS_EXTERN int
lws_get_child_pending_on_writable(const struct lws *wsi)
{

View file

@ -831,6 +831,7 @@ struct client_info_stash {
char *method;
char *iface;
char *alpn;
void *opaque_user_data; /* not allocated or freed by lws */
};
#endif
@ -915,6 +916,7 @@ struct lws {
#endif
void *user_space;
void *opaque_parent_data;
void *opaque_user_data;
struct lws_buflist *buflist; /* input-side buflist */
struct lws_buflist *buflist_out; /* output-side buflist */

View file

@ -1267,6 +1267,8 @@ lws_h2_parse_end_of_frame(struct lws *wsi)
h2n->swsi->user_space = wsi->user_space;
h2n->swsi->user_space_externally_allocated =
wsi->user_space_externally_allocated;
h2n->swsi->opaque_user_data = wsi->opaque_user_data;
wsi->opaque_user_data = NULL;
wsi->user_space = NULL;

View file

@ -928,6 +928,8 @@ lws_http_client_connect_via_info2(struct lws *wsi)
if (!stash)
return wsi;
wsi->opaque_user_data = wsi->stash->opaque_user_data;
/*
* we're not necessarily in a position to action these right away,
* stash them... we only need during connect phase so into a temp