mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-18 19:41:09 +00:00
API change -- Remove first ctx argument and add event mask to callback
There really does not exist a good reason for us sending a `uev_ctx_t *` pointer as the first argument to event callbacks. If the callback needs to reference the context, it can find the ctx pointer in the `uev_t *w`. This patch removes the first argument from all callbacks and also fixes a slight bug in that the event loop never returned the actual event that triggered the callback! Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
9e7f6865fc
commit
1f9558059a
6 files changed
+30
-24
No files matched your search
+10
-6
@@ -69,13 +69,13 @@ static int callback(arg_t *arg, int event, void *foo)
|
||||
return 42;
|
||||
}
|
||||
|
||||
static void sigsegv_cb(uev_ctx_t *UNUSED(ctx), uev_t *UNUSED(w), void *UNUSED(arg), int UNUSED(events))
|
||||
static void sigsegv_cb(uev_t *UNUSED(w), void *UNUSED(arg), int UNUSED(events))
|
||||
{
|
||||
warnx("PID %d caused segfault.", getpid());
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
static void sigchld_cb(uev_ctx_t *UNUSED(ctx), uev_t *UNUSED(w), void *UNUSED(arg), int UNUSED(events))
|
||||
static void sigchld_cb(uev_t *UNUSED(w), void *UNUSED(arg), int UNUSED(events))
|
||||
{
|
||||
pid_t pid = waitpid(-1, NULL, WNOHANG);
|
||||
|
||||
@@ -83,7 +83,7 @@ static void sigchld_cb(uev_ctx_t *UNUSED(ctx), uev_t *UNUSED(w), void *UNUSED(ar
|
||||
warnx("PID %d exited, bye.", pid);
|
||||
}
|
||||
|
||||
static void work_cb(uev_ctx_t *UNUSED(ctx), uev_t *UNUSED(w), void *arg, int UNUSED(events))
|
||||
static void work_cb(uev_t *UNUSED(w), void *arg, int UNUSED(events))
|
||||
{
|
||||
int status = 0;
|
||||
pid_t pid;
|
||||
@@ -102,15 +102,17 @@ static void work_cb(uev_ctx_t *UNUSED(ctx), uev_t *UNUSED(w), void *arg, int UNU
|
||||
if (WIFEXITED(status))
|
||||
printf("Child exited normally => %d\n", WEXITSTATUS(status));
|
||||
else if (WCOREDUMP(status))
|
||||
printf("Child crashed!\n");
|
||||
printf("Child crashed! %s\n", DO_SEGFAULT
|
||||
? "As expected, everything is OK."
|
||||
: "This should not happen!");
|
||||
else
|
||||
printf("Child did not exit normally!\n");
|
||||
}
|
||||
|
||||
static void exit_cb(uev_ctx_t *ctx, uev_t *UNUSED(w), void *UNUSED(arg), int UNUSED(events))
|
||||
static void exit_cb(uev_t *w, void *UNUSED(arg), int UNUSED(events))
|
||||
{
|
||||
printf("Process deadline reached, exiting!\n");
|
||||
uev_exit(ctx);
|
||||
uev_exit(w->ctx);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
@@ -120,6 +122,8 @@ int main(void)
|
||||
|
||||
/* Initialize libuEv */
|
||||
uev_init(&ctx);
|
||||
|
||||
/* Setup callbacks */
|
||||
uev_signal_init(&ctx, &sigsegv_watcher, sigsegv_cb, NULL, SIGSEGV);
|
||||
uev_signal_init(&ctx, &sigchld_watcher, sigchld_cb, NULL, SIGCHLD);
|
||||
uev_timer_init(&ctx, &timeout_watcher, work_cb, &arg, 400, 0);
|
||||
|
||||
Reference in new issue
Block a user