Mercurial > hg > dhcpcd
changeset 2991:c97ce8019371 draft
Requeue events when using epoll.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Thu, 05 Mar 2015 15:07:21 +0000 |
| parents | e329d287187c |
| children | 1c2bfb96fd3f |
| files | eloop.c eloop.h |
| diffstat | 2 files changed, 39 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/eloop.c Thu Mar 05 11:34:47 2015 +0000 +++ b/eloop.c Thu Mar 05 15:07:21 2015 +0000 @@ -359,14 +359,13 @@ ctx->exitnow = 1; } -#ifdef HAVE_KQUEUE +#if defined(HAVE_KQUEUE) || defined(HAVE_EPOLL) static int -eloop_kqueue_open(struct eloop_ctx *ctx) +eloop_open(struct eloop_ctx *ctx) { -#ifdef HAVE_KQUEUE1 - if ((ctx->poll_fd = kqueue1(O_CLOEXEC)) == -1) - return -1; -#else +#if defined(HAVE_KQUEUE1) + return (ctx->poll_fd = kqueue1(O_CLOEXEC)); +#elif defined(HAVE_KQUEUE) int i; if ((ctx->poll_fd = kqueue()) == -1) @@ -378,23 +377,30 @@ ctx->poll_fd = -1; return -1; } -#endif return ctx->poll_fd; +#elif defined (HAVE_EPOLL) + return (ctx->poll_fd = epoll_create1(EPOLL_CLOEXEC)); +#endif } int eloop_requeue(struct eloop_ctx *ctx) { + struct eloop_event *e; + int error; +#if defined(HAVE_KQUEUE) size_t i; - struct eloop_event *e; struct kevent *ke; - int error; +#elif defined(HAVE_EPOLL) + struct epoll_event epe; +#endif - close(ctx->poll_fd); - if (eloop_kqueue_open(ctx) == -1) + if (ctx->poll_fd != -1) + close(ctx->poll_fd); + if (eloop_open(ctx) == -1) return -1; - +#if defined (HAVE_KQUEUE) i = 0; while (dhcpcd_handlesigs[i]) i++; @@ -424,6 +430,22 @@ error = kevent(ctx->poll_fd, ke, LENC(i), NULL, 0, NULL); free(ke); + +#elif defined(HAVE_EPOLL) + + error = 0; + TAILQ_FOREACH(e, &ctx->events, next) { + memset(&epe, 0, sizeof(epe)); + epe.data.fd = e->fd; + epe.events = EPOLLIN; + if (e->write_cb) + epe.events |= EPOLLOUT; + epe.data.ptr = e; + if (epoll_ctl(ctx->poll_fd, EPOLL_CTL_ADD, e->fd, &epe) == -1) + error = -1; + } +#endif + return error; } #endif @@ -445,21 +467,13 @@ TAILQ_INIT(&ctx->timeouts); TAILQ_INIT(&ctx->free_timeouts); ctx->exitcode = EXIT_FAILURE; -#if defined(HAVE_KQUEUE) - /* requeue will put our signals in place */ - if (eloop_kqueue_open(ctx) == -1 || - eloop_requeue(ctx) == -1) - { +#if defined(HAVE_KQUEUE) || defined(HAVE_EPOLL) + ctx->poll_fd = -1; +#endif + if (eloop_requeue(ctx) == -1) { free(ctx); return NULL; } -#elif defined(HAVE_EPOLL) - if ((ctx->poll_fd = epoll_create1(EPOLL_CLOEXEC)) == -1) { - free(ctx); - return NULL; - } -#endif - } return ctx;
--- a/eloop.h Thu Mar 05 11:34:47 2015 +0000 +++ b/eloop.h Thu Mar 05 15:07:21 2015 +0000 @@ -100,7 +100,7 @@ int eloop_timeout_add_now(struct eloop_ctx *, void (*)(void *), void *); void eloop_q_timeout_delete(struct eloop_ctx *, int, void (*)(void *), void *); struct eloop_ctx * eloop_init(void); -#ifdef HAVE_KQUEUE +#if defined(HAVE_KQUEUE) || defined(HAVE_EPOLL) int eloop_requeue(struct eloop_ctx *); #else #define eloop_requeue(a) (0)
