[Libwebsockets] Modifying libwebsocket.user_space

Roger Light roger at atchoo.org
Mon Aug 18 18:58:24 CEST 2014


I'm in the situation where events outside of lws may require me to
update the contents of the user_space member of a single struct
libwebsocket. Any suggestions on how to proceed?

I have a struct that represents a client in my application. It keeps a
pointer to the wsi struct.

The easiest solution from my point of view would be the creation of a
libwebsocket_get_user() function. I see that this has been discussed
before (e.g. http://ml.libwebsockets.org/pipermail/libwebsockets/2013-February/000240.html
) and dismissed. I understand the reasoning there, but at least in my
case if service had cleaned up and freed the wsi, then my client
struct would also have been freed and I wouldn't be in this situation.
This is all single threaded, right? :)

My suggested solution is below, but I'd be happy to hear other ideas.

If there was a version of libwebsocket_callback_all_protocol()
available that let me pass in something that would end up in the
"user" and/or "in" arguments of my callback then I think it would
remove any risk of a bad wsi access and I wouldn't grumble *too* much
about having to iterate over all of the clients just to find the one I
was interested in. It would certainly be a huge improvement over the
horrific hack that I'm using at the moment.



More information about the Libwebsockets mailing list