[Libwebsockets] user parameter in protocol callback

Andy Green andy at warmcat.com
Thu Oct 1 17:27:16 CEST 2020

On 10/1/20 4:09 PM, Joel Winarske wrote:
> Hello,
> How does one pass an opaque data pointer so it shows up *everytime* as 
> the "user" parameter in the protocol callback? I've tried a few 
> variations and am not seeing a consistent pattern.
> I do see a consistent pattern when setting the opaque_user_data in 
> lws_client_connect_info, and accessing it with lws_get_opaque_user_data.

They are different things.

For client connections, you decide you want to create one and can tag it 
with whatever opaque user data


and / or userdata you want at creation time


Typically, you want the userdata assigned automatically, because its 
size depends on the protocol and eg for ws, that is something negotiated 
at connection time, not creation time.

For server connections, they are happening randomly and not under your 
control.  You probably want the automatic userdata allocated based again 
on negotiated protocol.

There are various kinds of events that can call your callback, some of 
them like PROTOCOL_INIT are not really related to any wsi at all, a fake 
wsi is passed in so you can at least always get the context and vhost 
from it.  You shouldn't assume that only wsi you have tagged appear there.


> Thanks,
> Joel
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets

More information about the Libwebsockets mailing list