lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Ya, I'm pretty sure that libev uses the "self pipe trick" [1]... I do
know that it guarantees to deliver signals as just another event in
the event loop and therefore are not subject to all the "normal" race
conditions.

Anyways, the code that I wrote last night (Pacific Time) is simply
code that adds another watcher type that already was a part of libev,
it just wasn't exposed as part of lua-ev yet.

Cheers,
-Brian

[1] http://cr.yp.to/docs/selfpipe.html

On Tue, Apr 13, 2010 at 5:27 AM, Tony Finch <dot@dotat.at> wrote:
> On Tue, 13 Apr 2010, Sean Conner wrote:
>>
>>   Signal handling is hard to do in general.
>
> In the context of an event loop, it's best to convert signals to something
> that can be select()ed on like other events. For example,
>
>        int sigsock[2];
>
>        void handler(int sig) {
>                unsigned char byte = sig;
>                write(sigsock[1], &byte, 1);
>        }
>
>        // ...
>
>        if(socketpair(AF_UNIX, SOCK_STREAM, 0, sigsock) < 0)
>                err(1, "socketpair");
>
>        struct sigaction sa;
>        sa.sa_handler = handler;
>        sa.sa_flags = 0;
>        sigemptyset(&sa.sa_mask);
>        if(sigaction(SIGWHATEVER, &sa, NULL) < 0)
>                err(1, "sigaction");
>
>        // then select() for readability of sigsock[0] to receive signals
>
> libevent does something along these lines albeit more elaborate.
>
> Tony.
> --
> f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
> GERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.
> MODERATE OR GOOD.
>



-- 
Brian Maher >> Glory to God <<