[Libwebsockets] lws_cancel_service() and libev

Olivier Langlois olivier at olivierlanglois.net
Sat Feb 15 23:58:57 CET 2020


Hi,

thx, for the prompt replies. I got a bad flu which basically forced me
to rest for pretty much the whole sleep.

On Mon, 2020-02-10 at 00:16 +0000, Andy Green wrote:
> On February 9, 2020 10:31:19 PM GMT, Olivier Langlois <
> olivier at olivierlanglois.net
> > wrote:
> > I have found out that lws_cancel_service() wasn't cancelling
> > foreign
> > loops.
> > 
> > To workaround this, here is what I had to do:
> > 
> > 1. Create my loop outside lws and pass it through foreign_loops
> > when
> > creating my lws_context
> > 2. Handle LWS_CALLBACK_EVENT_WAIT_CANCELLED and call ev_break()
> > from my
> > callback.
> > 
> > Maybe this is something that lws could handle itself. This is
> 
> ... lws_cancel_service() just says it's going to get you the
> EVENT_WAIT_CANCELLED callback from the event loop context, whatever
> that may be.  If that's coming quickly after the call, via the pipe()
> set up for that, it's doing what it's supposed to from lws
> perspective.  It should be able to do that for all event lib
> backends, even rtos that doesn't have a wait-integrated pipe() by
> using lo-bound UDP for the same purpose, because the pipe or udp
> socket fd is a participant on the event loop.
> 
> > definitely a call from the architect in chief but if I was to
> > imagine
> > how it could be done, I would say:
> > 
> > a) Add a cancel operation to the event-libs ops
> > b) call the cancel operation from the roles/pipe code where
> > LWS_CALLBACK_EVENT_WAIT_CANCELLED is called.
> > 
> > Now fixing lws_cancel_service() for libev is causing another
> > problem:
> 
> ... I don't understand what you think is broken that this
> 'fixes'.  We already evidently cancelled the event loop wait since we
> woke up and did the callback.

If what I am saying isn't clear then maybe it is that the contract
proposed by lws_service() isn't really understood by me and clarifying
documentation about that could be useful.

lws_service() never returns when a foreign loop is used. My
expectation, and tell me if it is unreasonable, is that by calling
lws_cancel_service() would wake up my service thread and make it return
from lws_service().

If calling lws_cancel_service() doesn't cancel the service, IMHO,
something is wrong with that.

Greetings,



More information about the Libwebsockets mailing list