[Libwebsockets] Complex issue with combinations of client/server push and pull

Andy Green andy at warmcat.com
Wed May 16 20:24:34 CEST 2018



On May 17, 2018 1:51:31 AM GMT+08:00, jon at keyonsec.com wrote:
>Hello Andy/all,
>
> 
>
>Complex issue so I'm going to try to make this as clear as I can,
>please
>forgive me if I need to clarify. I currently perform both push (server
>to
>client) and pull (client requests from server) actions in my app. 
>
> 
>
>On the pulls, I use the RECEIVE and WRITABLE callbacks along with
>lws_callback_on_writable and  'pss->' and everything works well.  On
>the
>pushes I use the lws_callback_on_writable_all_protocol and the
>lws_service
>functions and because with the pushes I haven't been interested in
>taking
>advantage of the 'pss->' variable everything has been fine.
>
> 
>
>However, I have a new function that sends something potentially
>different
>out to each client when I do a single push, and I want 'pss->' to tell
>me
>what to push. As my initial call in sequence for this function is a
>pull, I
>am able to save each client's state in 'pss->' off the init which is
>good.
>However, for each ensuing push I'm competing with other pushes from
>other
>functions and today I only have a generic 'lws_write' call that handles
>all
>pushes. So my problem is that if I'm not differentiating between the
>types
>of pushes that I'm doing that I cannot use the 'pss->' variable when I
>need
>to. 
>
> 
>
>If I use a global variable, I'm concerned it's going to get messed up
>on
>timing issues with the other pushes/pulls. I'm sure there's a better
>way but
>just don't know it. Pls advise. Thanks.

The actual user code is out of scope for me, as long as the library is doing its job.

However there are getting on for 40 worked examples now for how to do various application patterns with lws in ./minimal-examples in v3.0+.  I don't really understand your problem but many examples show how to use a "vhd", which is a user-defined struct specific to the vhost protocol instance, and how to get config data into the vhd cleanly even if it's instantiated in a dynamic plugin.  Others show how to use struct lws_ring to store and distribute arbitrary data to multiple clients safely.  Even proxying.

So study these...

https://github.com/warmcat/libwebsockets/tree/master/minimal-examples

-Andy

> 
>
>Jon



More information about the Libwebsockets mailing list