[Libwebsockets] user data

Casey Banner kcbanner at gmail.com
Thu Jan 16 17:14:48 CET 2020


I believe you manage the memory for the user data, so it's up to you
to ensure it's valid in this case. You could use a handle system and
pass that as your user data instead, or don't deallocate your user
data until the lws connection has been fully cleaned up.

On Thu, Jan 16, 2020 at 11:07 AM Peiffer Eric
<eric.peiffer at al-enterprise.com> wrote:
>
> Hi,
>
> I'm writing a websocket server based on libwebsockets.
>
> my protcols array look like this:
>
> static struct lws_protocols protocols[] = {
>         LWS_PLUGIN_HTTP,
>         LWS_PLUGIN_PROTOCOL_XMPP,
>         {NULL, NULL, 0, 0} /* terminator */
> };
>
> where the XMPP protocol is:
> #define LWS_PLUGIN_PROTOCOL_XMPP \
>
>     { \
>         "xmpp", \
>         callback_xmpp, \
>         sizeof(WebSocketInstance), \
>         0, \
>         0, NULL, 0 \
>     }
>
> WebSocketInstance is a C++ class that holds connection data.
>
> in the callback_xmpp I have the following code in order to retreive user data stored in the WebSocketInstance class:
>
> int callback_xmpp(struct lws *wsi, enum lws_callback_reasons reason,
>                   void *user, void *in, size_t len) {
>     try {
>
>         WebSocketInstance * connection =
>                 (WebSocketInstance *)user;
>
> .......
>
>
> I would like to know if there are an event that warms us that the data pointed by user will be deallocated?
>
> Regards,
>
> Eric
>
>
>
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets


More information about the Libwebsockets mailing list