Sleeping forever

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Sleeping forever

Laurent FAILLIE
Hello,

I'm writting a bridge from incoming MQTT messages (using paho.mqtt library) to Postgresql database insertion using pgmoon.

As this tool will be only even driven and as all the processing will be done in the MQTT callback, my tool will have nothing to do in its main loop.

Which is the best way the handle this infinite "do nothing" ? The target system is Linux so I can obviously use POSIX stuffs.

Thanks

Laurent
Reply | Threaded
Open this post in threaded view
|

Re: Sleeping forever

Sean Conner
It was thus said that the Great Laurent FAILLIE once stated:
> Hello,

> I'm writting a bridge from incoming MQTT messages (using paho.mqtt
> library) to Postgresql database insertion using pgmoon. As this tool will
> be only even driven and as all the processing will be done in the MQTT
> callback, my tool will have nothing to do in its main loop. Which is the
> best way the handle this infinite "do nothing" ? The target system is
> Linux so I can obviously use POSIX stuffs.

  Well ... several ways ...

        while(1)
          pause();

  This will sleep until the next signal happens.  

        while(1)
          select(0,NULL,NULL,NULL,0);

  will also block indefinitely unless a signal happens (and system calls
aren't restarted as an option).

        while(1)
          sleep(UINT_MAX);

will sleep until a signal happens.  This may use SIGALRM so avoid if you
need to handle that signal.

        while(1)
          clock_nanosleep(
                CLOCK_REALTIME,
                TIMER_ABSTIME,
                (strct timespec)&{
                        .tv_sec = (time_t)-1,
                        .tv_nsec = 0
                },
                NULL);
Like the sleep() one, only it doesn't use SIGALRM.  

  My preference is for calling pause().  

  -spc


Reply | Threaded
Open this post in threaded view
|

Re: Sleeping forever

Daurnimator
In reply to this post by Laurent FAILLIE
On 28 February 2018 at 11:20, Laurent FAILLIE <[hidden email]> wrote:

> Hello,
>
> I'm writting a bridge from incoming MQTT messages (using paho.mqtt library)
> to Postgresql database insertion using pgmoon.
>
> As this tool will be only even driven and as all the processing will be done
> in the MQTT callback, my tool will have nothing to do in its main loop.
>
> Which is the best way the handle this infinite "do nothing" ? The target
> system is Linux so I can obviously use POSIX stuffs.
>
> Thanks
>
> Laurent

I did a thing similar recently as a demo.

I used cqueues + https://github.com/flukso/lua-mosquitto
You could use https://github.com/daurnimator/cqueues-pgsql to do the
writing to postgres.

Reply | Threaded
Open this post in threaded view
|

Re: Sleeping forever

Russell Haley
On Tue, Feb 27, 2018 at 7:09 PM, Daurnimator <[hidden email]> wrote:

> On 28 February 2018 at 11:20, Laurent FAILLIE <[hidden email]> wrote:
>> Hello,
>>
>> I'm writting a bridge from incoming MQTT messages (using paho.mqtt library)
>> to Postgresql database insertion using pgmoon.
>>
>> As this tool will be only even driven and as all the processing will be done
>> in the MQTT callback, my tool will have nothing to do in its main loop.
>>
>> Which is the best way the handle this infinite "do nothing" ? The target
>> system is Linux so I can obviously use POSIX stuffs.
>>
>> Thanks
>>
>> Laurent
>
> I did a thing similar recently as a demo.
>
> I used cqueues + https://github.com/flukso/lua-mosquitto
> You could use https://github.com/daurnimator/cqueues-pgsql to do the
> writing to postgres.
>
+1 for cqueues and anything that uses it. Brilliant stuff that.

Russ

Reply | Threaded
Open this post in threaded view
|

Re: Sleeping forever

Laurent FAILLIE
Hum, what a can see from cqueue is it requieres Lua 5.2 isn't it ?
My systems are still under 5.1


Le mercredi 28 février 2018 à 07:02:07 UTC+1, Russell Haley <[hidden email]> a écrit :


On Tue, Feb 27, 2018 at 7:09 PM, Daurnimator <[hidden email]> wrote:

> On 28 February 2018 at 11:20, Laurent FAILLIE <[hidden email]> wrote:
>> Hello,
>>
>> I'm writting a bridge from incoming MQTT messages (using paho.mqtt library)
>> to Postgresql database insertion using pgmoon.
>>
>> As this tool will be only even driven and as all the processing will be done
>> in the MQTT callback, my tool will have nothing to do in its main loop.
>>
>> Which is the best way the handle this infinite "do nothing" ? The target
>> system is Linux so I can obviously use POSIX stuffs.
>>
>> Thanks
>>
>> Laurent
>
> I did a thing similar recently as a demo.
>
> I used cqueues + https://github.com/flukso/lua-mosquitto
> You could use https://github.com/daurnimator/cqueues-pgsql to do the
> writing to postgres.

>
+1 for cqueues and anything that uses it. Brilliant stuff that.

Russ


Reply | Threaded
Open this post in threaded view
|

Re: Sleeping forever

Laurent FAILLIE
Ok, thanks.
Let's go for Pause :)

Le mercredi 28 février 2018 à 12:42:20 UTC+1, Laurent FAILLIE <[hidden email]> a écrit :


Hum, what a can see from cqueue is it requieres Lua 5.2 isn't it ?
My systems are still under 5.1


Le mercredi 28 février 2018 à 07:02:07 UTC+1, Russell Haley <[hidden email]> a écrit :


On Tue, Feb 27, 2018 at 7:09 PM, Daurnimator <[hidden email]> wrote:

> On 28 February 2018 at 11:20, Laurent FAILLIE <[hidden email]> wrote:
>> Hello,
>>
>> I'm writting a bridge from incoming MQTT messages (using paho.mqtt library)
>> to Postgresql database insertion using pgmoon.
>>
>> As this tool will be only even driven and as all the processing will be done
>> in the MQTT callback, my tool will have nothing to do in its main loop.
>>
>> Which is the best way the handle this infinite "do nothing" ? The target
>> system is Linux so I can obviously use POSIX stuffs.
>>
>> Thanks
>>
>> Laurent
>
> I did a thing similar recently as a demo.
>
> I used cqueues + https://github.com/flukso/lua-mosquitto
> You could use https://github.com/daurnimator/cqueues-pgsql to do the
> writing to postgres.

>
+1 for cqueues and anything that uses it. Brilliant stuff that.

Russ