mirror of
https://github.com/troglobit/libuev.git
synced 2026-10-09 16:50:26 +07:00
Reverse christmas tree and simplify a bit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
@@ -314,16 +314,16 @@ static void joystick_cb(uev_t *w, void *arg, int events)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int fd;
|
||||
uev_t watcher;
|
||||
uev_ctx_t ctx;
|
||||
uev_t js;
|
||||
int fd;
|
||||
|
||||
fd = open("/dev/input/js0", O_RDONLY, O_NONBLOCK);
|
||||
if (fd < 0)
|
||||
errx(errno, "Cannot find a joystick attached.");
|
||||
|
||||
uev_init(&ctx);
|
||||
uev_io_init(&ctx, &watcher, joystick_cb, NULL, fd, UEV_READ);
|
||||
uev_io_init(&ctx, &js, joystick_cb, NULL, fd, UEV_READ);
|
||||
|
||||
puts("Starting, press Ctrl-C to exit.");
|
||||
|
||||
|
||||
+3
-3
@@ -74,16 +74,16 @@ static void joystick_cb(uev_t *w, void *arg, int events)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int fd;
|
||||
uev_t js1_watcher;
|
||||
uev_ctx_t ctx;
|
||||
uev_t js1;
|
||||
int fd;
|
||||
|
||||
fd = open("/dev/input/js0", O_RDONLY, O_NONBLOCK);
|
||||
if (fd < 0)
|
||||
errx(errno, "Cannot find a joystick attached.");
|
||||
|
||||
uev_init(&ctx);
|
||||
uev_io_init(&ctx, &js1_watcher, joystick_cb, NULL, fd, UEV_READ);
|
||||
uev_io_init(&ctx, &js1, joystick_cb, NULL, fd, UEV_READ);
|
||||
|
||||
puts("Starting, press Ctrl-C to exit.");
|
||||
|
||||
|
||||
+2
-2
@@ -47,9 +47,9 @@ void process_stdin(uev_t *w, void *arg, int events)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
uev_t watcher;
|
||||
uev_ctx_t ctx;
|
||||
uev_t watcher;
|
||||
int ret;
|
||||
|
||||
uev_init(&ctx);
|
||||
|
||||
|
||||
+1
-1
@@ -42,8 +42,8 @@
|
||||
*/
|
||||
int uev_signal_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int signo)
|
||||
{
|
||||
int fd;
|
||||
sigset_t mask;
|
||||
int fd;
|
||||
|
||||
if (!w || !ctx) {
|
||||
errno = EINVAL;
|
||||
|
||||
@@ -289,8 +289,8 @@ int uev_exit(uev_ctx_t *ctx)
|
||||
*/
|
||||
int uev_run(uev_ctx_t *ctx, int flags)
|
||||
{
|
||||
int timeout = -1;
|
||||
uev_t *w;
|
||||
int timeout = -1;
|
||||
|
||||
if (!ctx || ctx->fd < 0) {
|
||||
errno = EINVAL;
|
||||
@@ -312,8 +312,8 @@ int uev_run(uev_ctx_t *ctx, int flags)
|
||||
}
|
||||
|
||||
while (ctx->running && ctx->watchers) {
|
||||
int i, nfds, rerun = 0;
|
||||
struct epoll_event ee[UEV_MAX_EVENTS];
|
||||
int i, nfds, rerun = 0;
|
||||
|
||||
/* Handle special case: `application < file.txt` */
|
||||
if (ctx->workaround) {
|
||||
@@ -349,9 +349,9 @@ int uev_run(uev_ctx_t *ctx, int flags)
|
||||
}
|
||||
|
||||
for (i = 0; ctx->running && i < nfds; i++) {
|
||||
uint64_t exp;
|
||||
uint32_t events;
|
||||
struct signalfd_siginfo fdsi;
|
||||
uint32_t events;
|
||||
uint64_t exp;
|
||||
ssize_t sz = sizeof(fdsi);
|
||||
|
||||
w = (uev_t *)ee[i].data.ptr;
|
||||
|
||||
+1
-1
@@ -38,8 +38,8 @@ static void cb(uev_t *w, void *arg, int events)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uev_ctx_t ctx;
|
||||
struct timeval tomorrow;
|
||||
uev_ctx_t ctx;
|
||||
|
||||
gettimeofday(&tomorrow, NULL);
|
||||
tomorrow.tv_sec += 24 * 60 * 60;
|
||||
|
||||
+4
-4
@@ -33,8 +33,8 @@ struct timeval tv;
|
||||
|
||||
static void cron_job(uev_t *w, void *arg, int events)
|
||||
{
|
||||
static int laps = 3;
|
||||
struct timeval now;
|
||||
static int laps = 3;
|
||||
|
||||
if (UEV_ERROR == events)
|
||||
fprintf(stderr, "cron watcher failed, ignoring ...\n");
|
||||
@@ -54,10 +54,10 @@ static void cron_job(uev_t *w, void *arg, int events)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int rc;
|
||||
uev_t cron_watcher;
|
||||
uev_ctx_t ctx;
|
||||
time_t when, interval;
|
||||
uev_t cron;
|
||||
int rc;
|
||||
|
||||
uev_init(&ctx);
|
||||
|
||||
@@ -68,7 +68,7 @@ int main(void)
|
||||
printf("Expected cron %s", ctime(&when));
|
||||
|
||||
interval = INTERVAL;
|
||||
uev_cron_init(&ctx, &cron_watcher, cron_job, NULL, when, interval);
|
||||
uev_cron_init(&ctx, &cron, cron_job, NULL, when, interval);
|
||||
|
||||
rc = uev_run(&ctx, 0);
|
||||
fail_unless(result == 0);
|
||||
|
||||
+3
-3
@@ -81,8 +81,8 @@ static void sigchld_cb(uev_t *w, void *arg, int events)
|
||||
|
||||
static void work_cb(uev_t *w, void *arg, int events)
|
||||
{
|
||||
int status = 0;
|
||||
pid_t pid;
|
||||
pid_t pid;
|
||||
int status = 0;
|
||||
|
||||
pid = fork();
|
||||
if (-1 == pid)
|
||||
@@ -113,8 +113,8 @@ static void exit_cb(uev_t *w, void *arg, int events)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uev_t sigsegv_watcher, sigchld_watcher, timeout_watcher, deadline_watcher;
|
||||
uev_ctx_t ctx;
|
||||
uev_t sigsegv_watcher, sigchld_watcher, timeout_watcher, deadline_watcher;
|
||||
|
||||
/* Initialize libuEv */
|
||||
uev_init(&ctx);
|
||||
|
||||
+2
-2
@@ -23,9 +23,9 @@ static void cb(uev_t *w, void *arg, int events)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int rc;
|
||||
uev_t w;
|
||||
uev_ctx_t ctx;
|
||||
uev_t w;
|
||||
int rc;
|
||||
|
||||
uev_init(&ctx);
|
||||
uev_timer_init(&ctx, &w, cb, NULL, TIMEOUT * 1000, 0);
|
||||
|
||||
Reference in New Issue
Block a user