[Libevent-users] pause libevent?
Damien Miller
djm at mindrot.org
Fri Feb 9 21:46:21 EST 2007
On Fri, 9 Feb 2007, Adam Chou wrote:
> sorry, i misunderstood what i was reading, but thanks.
>
> with that resolved, i do have a couple of other questions:
> 1. when using signal_add(), how does the timeout parameter affect the signal
> handler? i've set it to handle sigalrm and a timeout of 2. if i send the
> process sigalrm, nothing happens. i wait 2 seconds and nothing happens. but
> if i set it to 0, then it responds to my sigalrm's that i send it
works for me. The attached test program produces the expected output: one
event after five seconds (SIGALRM) and a timeout event after 10.
> 2. when using struct event to event_set and event_add, am i supposed to use
> a different struct for each event?
Yes.
> sorry if this is something i should know. i'm just not understanding the
> documentation very well. thanks in advance for your help!
If you are in doubt, you might want to look at the libevent code itself
(it is very readable) or one of the applications that use it. I'm certainly
finding that helpful as I learn it :)
-d
-------------- next part --------------
#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <event.h>
void
cb(int fd, short ev, void *ctx)
{
fprintf(stderr, "ping! %d %hd\n", fd, ev);
}
int
main(int argc, char **argv)
{
struct event ev;
struct timeval tv;
event_init();
signal_set(&ev, SIGALRM, cb, NULL);
tv.tv_sec = 10;
tv.tv_usec = 0;
signal_add(&ev, &tv);
alarm(5);
event_dispatch();
fprintf(stderr, "done\n");
return 0;
}
More information about the Libevent-users
mailing list