[Libwebsockets] callback pointer

Trey Weaver treyweaver at fastmail.net
Fri May 14 21:23:15 CEST 2021


What is the best way to pass a pointer to a callback?

I want to set up a pointer to a class (i'm using c++) an retrieve that pointer when I get a callback.

I tried setting up the *protocols[0].user = this*; 

And I tried:
*lws_context_creation_info.user = this;*

And then looked at the *user data on the call back, but the pointers did not match.

I then looked at using: 
*lws_client_connect_info.opaque_user_data = this.*
and then use in the call back 
*ws_get_opaque_user_data(wsi);*

This worked ok, and I probably could live with it but I miss the pointer for the first three messages when I set up the context and first connect
*lws_client_connect_via_info*

These are the message that have no value from: ws_get_opaque_user_data(wsi);

LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS (0x0015)
LWS_CALLBACK_PROTOCOL_INIT (0x001b)
LWS_CALLBACK_CLIENT_HTTP_BIND_PROTOCOL (0x0055)

I was wondered if there was a better way.

Trey Weaver
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20210514/4b519476/attachment.htm>


More information about the Libwebsockets mailing list