[Libwebsockets] One thread for initializing and reading, another for writing

Harsha mynameissriharsha at gmail.com
Thu Oct 1 19:13:56 CEST 2015


Yea I agree. I use it with a queue as well. I push my messages to a queue. And when you get a LWS_CALLBACK_SERVER_WRITEABLE I drain the queue. 

Harsha

> On Oct 1, 2015, at 12:53 AM, Fabian Kurz <andy.green at linaro.org> wrote:
> 
>> On Thu, Oct 01, 2015 at 03:37:11PM +0800, Andrew Cooks wrote:
>>> On Wed, Sep 30, 2015 at 8:28 PM, MAHE Aubin wrote:
>>> I use a thread for reading on libwebsockets and another one for writing.
>>> [...]
>>> 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
>> 'LWS_CALLBACK_CLIENT_WRITEABLE',
>> 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.
> 
> I something similar, using Redis for the message queues. Works very
> well (and makes it trivially easy to use/process/change the data from
> other processes as well) and requires very little programming effort;
> just include hiredis and run a local redis instance.
> 
> BR
> Fabian
> 
> -- 
> Fabian Kurz, DJ1YFK      Munich, Germany
> fabian at fkurz.net         +49 176 24079617
> http://fkurz.net/        http://lcwo.net/
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> http://ml.libwebsockets.org/mailman/listinfo/libwebsockets



More information about the Libwebsockets mailing list