[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lib-ev vs. signal handling
- From: Tony Finch <dot@...>
- Date: Tue, 13 Apr 2010 13:27:04 +0100
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.