[Libwebsockets] One thread for initializing and reading, another for writing
acooks at linux.com
Thu Oct 1 09:37:11 CEST 2015
On Wed, Sep 30, 2015 at 8:28 PM, MAHE Aubin <andy.green at linaro.org> wrote:
> Hi All,
> I use a thread for reading on libwebsockets and another one for writing.
> More precisely, the first thread is dedicated to:
> http and user callbacks defined in struct libwebsocket_protocols
> The second thread uses only libwebsocket_write().
> Is this practice safe?
In README.coding.md there is a section that says that you should only
'send' when you receive the 'LWS_CALLBACK_SERVER_WRITEABLE' or
which I interpret to mean that it is not safe to call libwebsocket_write()
from another thread.
I'm new to libwebsockets too (so my solution might not be optimal), but for
my application I implemented a message queue that I could write to from
another thread and read from inside the 'LWS_CALLBACK_CLIENT_WRITEABLE'
callback. It took a bit of work to get the publish/subscribe mechanics to
work properly to support multiple clients.
I'd like to learn how others have approached this problem too.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Libwebsockets