Skip to content

Instantly share code, notes, and snippets.

@frozencemetery
Created August 25, 2017 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frozencemetery/155b05195b7177091c9144e7bbefb32e to your computer and use it in GitHub Desktop.
Save frozencemetery/155b05195b7177091c9144e7bbefb32e to your computer and use it in GitHub Desktop.
#include <tevent.h>
#include <stdio.h>
#include <unistd.h>
static void timer_cb(struct tevent_context *c, struct tevent_timer *e,
struct timeval ct, void *data) {
printf("[timer_cb]; error!\n");
exit(-1);
}
static void error_cb(struct tevent_context *c, struct tevent_fd *e,
uint16_t fl, void *data) {
printf("blue skied an' clear\n");
exit(0);
}
int main() {
int ret, fds[2];
struct tevent_context *c;
struct timeval tv;
struct tevent_timer *timer;
struct tevent_fd *tfd;
fds[0] = -1;
fds[1] = -1;
ret = pipe(fds);
if (ret != 0) {
printf("pipe\n");
exit(-1);
}
c = tevent_context_init(NULL);
if (!c) {
printf("tevent_context_init\n");
exit(-1);
}
tv = tevent_timeval_current_ofs(1, 1000);
timer = tevent_add_timer(c, c, tv, timer_cb, (void *) c);
if (!timer) {
printf("tevent_add_timer\n");
exit(-1);
}
close(fds[0]);
fds[0] = -1;
tfd = tevent_add_fd(c, c, fds[1], 0, error_cb, (void *) c);
if (!tfd) {
printf("tevent_add_fd\n");
exit(-1);
}
tevent_fd_set_flags(tfd, TEVENT_FD_WRITE);
while (1) {
printf("[tevent_loop_once]\n");
ret = tevent_loop_once(c);
if (ret) {
printf("tevent_loop_once\n");
exit(-1);
}
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment