[Libwebsockets] Determining the protocol's name from within a callback

"Andy Green (林安廸)" andy at warmcat.com
Fri Apr 12 19:15:01 CEST 2013


On 13/04/13 01:11, the mail apparently from Drew Noakes included:
> Hi,
>
> I'd like to reuse a callback across many protocols. I'm creating one
> protocol for each of a number of entity in my system dynamically,
> removing quite a bit of near-duplicated code.
>
> Within the callback I'll need to know which protocol I'm being called
> back for.

This guy will do it -->

LWS_VISIBLE LWS_EXTERN const struct libwebsocket_protocols * 

libwebsockets_get_protocol(struct libwebsocket *wsi);

> Can this be obtained from the wsi? I can't see how user session data
> would help, as that's also initialised within the callback.
> libwebsocket.h only provides a forward declaration for the wsi type,
> presumably to hide any details of its internals.

Right, the headers for lws are split into two, one private and one for 
user code that you know.  The private one has all the changeable struct 
definitions and keeps the confusing guts out of sight.

-Andy






More information about the Libwebsockets mailing list