client: allow change externally-defined wsi user_data

https://github.com/warmcat/libwebsockets/issues/819

AG: add explanation in doxygen comment and check user_space was externally set
This commit is contained in:
Lukas Geyer 2017-02-28 21:17:25 +08:00 committed by Andy Green
parent 6d0c96e06a
commit 16ee4b6f0d
2 changed files with 23 additions and 0 deletions

View file

@ -1374,6 +1374,16 @@ lws_wsi_user(struct lws *wsi)
return wsi->user_space;
}
LWS_VISIBLE LWS_EXTERN void
lws_set_wsi_user(struct lws *wsi, void *data)
{
if (wsi->user_space_externally_allocated)
wsi->user_space = data;
else
lwsl_err("%s: Cannot set internally-allocated user_space\n",
__func__);
}
LWS_VISIBLE LWS_EXTERN struct lws *
lws_get_parent(const struct lws *wsi)
{

View file

@ -3902,6 +3902,19 @@ lws_get_library_version(void);
LWS_VISIBLE LWS_EXTERN void *
lws_wsi_user(struct lws *wsi);
/**
* lws_wsi_set_user() - set the user data associated with the client connection
* \param wsi: lws connection
* \param user: user data
*
* By default lws allocates this and it's not legal to externally set it
* yourself. However client connections may have it set externally when the
* connection is created... if so, this api can be used to modify it at
* runtime additionally.
*/
LWS_VISIBLE LWS_EXTERN void
lws_set_wsi_user(struct lws *wsi, void *user);
/**
* lws_parse_uri: cut up prot:/ads:port/path into pieces
* Notice it does so by dropping '\0' into input string