[Libwebsockets] libwebsockets_broadcast

Andy Green andy at warmcat.com
Tue Mar 26 20:31:12 CET 2013

Hi -

No the wsi holding thing isn't good, because the connection can have been closed, and the wsi freed any time.  Afterwards the other thread can try to pass invalid wsi into the library.

The safe way is perform wsi operations with a wsi that was handed to you in the callback, from within the callback.  It's also safe to do operations on a protocol inside your service loop, ie  call the callback-all-connections-of-this-protocol api from your service loop.

You can synchronize calling it from your service loop and other thread by polling, if that's too much latency you can use a socket or file from the other thread using the external polling loop stuff to signal and pass data between the threads.

It's better to eliminate your other thread at do it all in the service loop directly.


Michel Archambault <marchamb at matrox.com> wrote:

>I have an application that generates data in one thread (name it the
>"broadcast thread").
>Previously, I used libwebsockets_broadcast() to sent this data to all
>clients connected, but this function has been removed.
>What is the good way to do that now?
>Should I maintain a list of active clients (wsi), that my "broadcast
>thread" will use to call libwebsocket_write() for each one of them?
>Thank you!
>Michel Archambault
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20130327/e400826e/attachment-0001.html>

More information about the Libwebsockets mailing list