[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re[2]: lib-ev vs. signal handling
- From: Arseny Vakhrushev <arseny.vakhrushev@...>
- Date: Tue, 13 Apr 2010 17:54:25 +0400
There are two other ways to turn the flow of signals into an event loop like select/poll/epoll:
1. use the pselect()/ppoll() syscalls in a couple with proper calls to pthread_sigmask() to allow only
certain threads to receive signals
2. use the signalfd() syscall and put the resulting fd to the list of fd's which is used by
select/poll
Socket pairs are fine too because they are more portable.
Best regards,
Arseny
-----------------------------------------------------------
> 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.
>>