[Libwebsockets] R: Question about timer
stefano.mora at newdep.com
Wed Jul 24 18:49:46 CEST 2019
Ok, thanks a lot!
I this new way do I need to setup a timer for each client or only one for everyone?
The generated callback is LWS_CALLBACK_TIMER or LWS_CALLBACK_USER (eg) ?
Da: Andy Green <andy at warmcat.com>
Inviato: mercoledì 24 luglio 2019 17:34
A: libwebsockets at ml.libwebsockets.org <libwebsockets at ml.libwebsockets.org>; Stefano Mora <stefano.mora at newdep.com>; libwebsockets at ml.libwebsockets.org <libwebsockets at ml.libwebsockets.org>
Oggetto: Re: [Libwebsockets] Question about timer
On July 24, 2019 7:57:29 AM PDT, Stefano Mora <stefano.mora at newdep.com> wrote:
>in my application I start the timer with:
> lws_set_timer_usecs( wsi, TIMER_USECS);
>and this is ok.
>A second client connects the server and, since it is running, it do not
>start another timer.
>This is ok and the timer continues to flow thanks to:
> lwsl_user("LWS_CB_TIMER t:%d\n", engineData.timer);
> lws_set_timer_usecs( wsi, engineData.timer ? TIMER_USECS : -1);
>But, when a client disconnects the TIMER 'reason' stops to coming (the
>last engineData.timer I see is 1) and the other client is running
>without the timer.
>I'm pretty sure I do not disable the timer.
>I my understanding the timer is a server-wide object, I mean it not
>referred to a particular client, is it?
No... this "hi res" timer is available for each wsi... there is actually a single sorted queue of pending timers on each pt... this is used to restrict the sleep time for the event loop wait to that of the earliest pending timer.
But any wsi can participate on it independently. Each wsi only sees hires timer callbacks that he personally asked for, hence the api takes the wsi as the argument.
There's a separate second-resolution timer that belongs to the vhost - protocol combination instead of each wsi that sounds more like what you want
Using that api either wsi instance will be setting a timer that will fire independent of their own lifecycle. Note that because of that, when it fires and calls back with 'reason' (eg, LWS_CALLBACK_USER) it is called with a fake wsi that only has context, vhost and protocol set on it. By then, there may no longer be any live wsis using it, but that won't stop it coming. So it's useful for eg, client connect retries etc.
>Any idea why the timer stops?
IIUI it's correct, you want the other timer api.
>Stefano Mora / SW Engineer
>stefano.mora at newdep.com<mailto:stefano.mora at newdep.com>
>NEWDEP S.r.l. – SOFTWARE & ENGINEERING SERVICES
>Office: +39 0521 1756855/ Fax: +39 0521 631414
>Sede legale ed operativa: Via Monte Aquila, 2/B - 43124 Parma - ITALY
>Il presente messaggio, corredato dei relativi allegati, contiene
>informazioni strettamente riservate ai sensi del D.L.gs. 196/2003 ed è
>destinato esclusivamente ai destinatari. Chiunque ricevesse questo
>messaggio per errore è pregato di darne gentilmente comunicazione al
>mittente, di non copiarlo, divulgarlo o distribuirlo, nonchè di
>This communication may contain confidential and/or otherwise
>proprietary material and is thus for use only by the intended
>recipient. If you received this in error, please contact the sender and
>delete the e-mail and its attachments from all computers.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Libwebsockets