deleting events.
return;
if (state->arp_fd != -1) {
- eloop_event_delete(ifp->ctx->eloop, state->arp_fd, 0);
+ eloop_event_delete(ifp->ctx->eloop, state->arp_fd);
close(state->arp_fd);
state->arp_fd = -1;
}
{
TAILQ_REMOVE(&fd->ctx->control_fds, fd, next);
- eloop_event_delete(fd->ctx->eloop, fd->fd, 0);
+ eloop_event_delete(fd->ctx->eloop, fd->fd);
close(fd->fd);
control_queue_free(fd);
free(fd);
if (ctx->control_fd == -1)
return 0;
- eloop_event_delete(ctx->eloop, ctx->control_fd, 0);
+ eloop_event_delete(ctx->eloop, ctx->control_fd);
close(ctx->control_fd);
ctx->control_fd = -1;
if (unlink(ctx->control_sock) == -1)
retval = -1;
if (ctx->control_unpriv_fd != -1) {
- eloop_event_delete(ctx->eloop, ctx->control_unpriv_fd, 0);
+ eloop_event_delete(ctx->eloop, ctx->control_unpriv_fd);
close(ctx->control_unpriv_fd);
ctx->control_unpriv_fd = -1;
if (unlink(UNPRIVSOCKET) == -1)
freeit:
while ((l = TAILQ_FIRST(&ctx->control_fds))) {
TAILQ_REMOVE(&ctx->control_fds, l, next);
- eloop_event_delete(ctx->eloop, l->fd, 0);
+ eloop_event_delete(ctx->eloop, l->fd);
close(l->fd);
control_queue_free(l);
free(l);
TAILQ_INSERT_TAIL(&fd->free_queue, data, next);
if (TAILQ_FIRST(&fd->queue) == NULL)
- eloop_event_delete(fd->ctx->eloop, fd->fd, 1);
+ eloop_event_remove_writecb(fd->ctx->eloop, fd->fd);
}
int
return;
if (state->raw_fd != -1) {
- eloop_event_delete(ifp->ctx->eloop, state->raw_fd, 0);
+ eloop_event_delete(ifp->ctx->eloop, state->raw_fd);
close(state->raw_fd);
state->raw_fd = -1;
}
* from the raw fd */
if (read(ctx->udp_fd, buffer, sizeof(buffer)) == -1) {
logger(ctx, LOG_ERR, "%s: %m", __func__);
- eloop_event_delete(ctx->eloop, ctx->udp_fd, 0);
+ eloop_event_delete(ctx->eloop, ctx->udp_fd);
close(ctx->udp_fd);
ctx->udp_fd = -1;
}
}
if (ifp == NULL) {
if (ctx->udp_fd != -1) {
- eloop_event_delete(ctx->eloop, ctx->udp_fd, 0);
+ eloop_event_delete(ctx->eloop, ctx->udp_fd);
close(ctx->udp_fd);
ctx->udp_fd = -1;
}
if (bytes == -1) {
logger(dctx, LOG_ERR, "%s: recvmsg: %m", __func__);
close(ctx->dhcp_fd);
- eloop_event_delete(dctx->eloop, ctx->dhcp_fd, 0);
+ eloop_event_delete(dctx->eloop, ctx->dhcp_fd);
ctx->dhcp_fd = -1;
return;
}
}
if (ifp == NULL && ctx->ipv6) {
if (ctx->ipv6->dhcp_fd != -1) {
- eloop_event_delete(ctx->eloop, ctx->ipv6->dhcp_fd, 0);
+ eloop_event_delete(ctx->eloop, ctx->ipv6->dhcp_fd);
close(ctx->ipv6->dhcp_fd);
ctx->ipv6->dhcp_fd = -1;
}
ctx = arg;
if (if_managelink(ctx) == -1) {
logger(ctx, LOG_ERR, "if_managelink: %m");
- eloop_event_delete(ctx->eloop, ctx->link_fd, 0);
+ eloop_event_delete(ctx->eloop, ctx->link_fd);
close(ctx->link_fd);
ctx->link_fd = -1;
}
}
if (write(fd->fd, &len, sizeof(len)) != sizeof(len))
return;
- eloop_event_delete(fd->ctx->eloop, fd->fd, 1);
+ eloop_event_remove_writecb(fd->ctx->eloop, fd->fd);
TAILQ_FOREACH(ifp, fd->ctx->ifaces, next) {
if (send_interface(fd, ifp) == -1)
logger(ifp->ctx, LOG_ERR,
}
free(ctx.duid);
if (ctx.link_fd != -1) {
- eloop_event_delete(ctx.eloop, ctx.link_fd, 0);
+ eloop_event_delete(ctx.eloop, ctx.link_fd);
close(ctx.link_fd);
}
e->write_cb_arg = write_cb_arg;
#if defined(HAVE_KQUEUE)
- EV_SET(&ke[0], (uintptr_t)fd, EVFILT_READ, EV_ADD, 0, 0, UPTR(e));
- if (write_cb)
+ if (read_cb != NULL)
+ EV_SET(&ke[0], (uintptr_t)fd, EVFILT_READ,
+ EV_ADD, 0, 0, UPTR(e));
+ if (write_cb != NULL)
EV_SET(&ke[1], (uintptr_t)fd, EVFILT_WRITE,
EV_ADD, 0, 0, UPTR(e));
if (kevent(eloop->poll_fd, ke, write_cb ? 2 : 1, NULL, 0, NULL) == -1)
}
void
-eloop_event_delete(struct eloop *eloop, int fd, int write_only)
+eloop_event_delete_write(struct eloop *eloop, int fd, int write_only)
{
struct eloop_event *e;
#if defined(HAVE_KQUEUE)
TAILQ_FOREACH(e, &eloop->events, next) {
if (e->fd == fd) {
- if (write_only) {
- if (e->write_cb) {
+ if (write_only && e->read_cb != NULL) {
+ if (e->write_cb != NULL) {
e->write_cb = NULL;
e->write_cb_arg = NULL;
#if defined(HAVE_KQUEUE)
EPOLL_CTL_MOD, fd, &epe);
#endif
}
-
} else {
TAILQ_REMOVE(&eloop->events, e, next);
#if defined(HAVE_KQUEUE)
#elif defined(HAVE_EPOLL)
if (n) {
e = (struct eloop_event *)epe.data.ptr;
- if (epe.events & EPOLLOUT && e->write_cb) {
+ if (epe.events & EPOLLOUT && e->write_cb != NULL) {
e->write_cb(e->write_cb_arg);
continue;
}
if (epe.events &
- (EPOLLIN | EPOLLERR | EPOLLHUP))
+ (EPOLLIN | EPOLLERR | EPOLLHUP) &&
+ e->read_cb != NULL)
{
e->read_cb(e->read_cb_arg);
continue;
if (n > 0) {
TAILQ_FOREACH(e, &eloop->events, next) {
if (e->pollfd->revents & POLLOUT &&
- e->write_cb)
+ e->write_cb != NULL)
{
e->write_cb(e->write_cb_arg);
break;
}
- if (e->pollfd->revents) {
+ if (e->pollfd->revents && e->read_cb != NULL) {
e->read_cb(e->read_cb_arg);
break;
}
int eloop_event_add(struct eloop *, int,
void (*)(void *), void *,
void (*)(void *), void *);
-void eloop_event_delete(struct eloop *, int, int);
+#define eloop_event_delete(eloop, fd) \
+ eloop_event_delete_write((eloop), (fd), 0)
+#define eloop_event_remove_writecb(eloop, fd) \
+ eloop_event_delete_write((eloop), (fd), 1)
+void eloop_event_delete_write(struct eloop *, int, int);
#define eloop_timeout_add_tv(eloop, tv, cb, ctx) \
eloop_q_timeout_add_tv((eloop), ELOOP_QUEUE, (tv), (cb), (ctx))
eloop_q_timeout_add_msec((eloop), ELOOP_QUEUE, (ms), (cb), (ctx))
#define eloop_timeout_delete(eloop, cb, ctx) \
eloop_q_timeout_delete((eloop), ELOOP_QUEUE, (cb), (ctx))
-int eloop_q_timeout_add_tv(struct eloop *, int queue,
+int eloop_q_timeout_add_tv(struct eloop *, int,
const struct timespec *, void (*)(void *), void *);
-int eloop_q_timeout_add_sec(struct eloop *, int queue,
+int eloop_q_timeout_add_sec(struct eloop *, int,
time_t, void (*)(void *), void *);
-int eloop_q_timeout_add_msec(struct eloop *, int queue,
+int eloop_q_timeout_add_msec(struct eloop *, int,
long, void (*)(void *), void *);
void eloop_q_timeout_delete(struct eloop *, int, void (*)(void *), void *);
eexit:
if (ctx->nd_fd != -1) {
- eloop_event_delete(dctx->eloop, ctx->nd_fd, 0);
+ eloop_event_delete(dctx->eloop, ctx->nd_fd);
close(ctx->nd_fd);
ctx->nd_fd = -1;
}
}
if (ifp == NULL) {
if (ctx->ipv6->nd_fd != -1) {
- eloop_event_delete(ctx->eloop, ctx->ipv6->nd_fd, 0);
+ eloop_event_delete(ctx->eloop, ctx->ipv6->nd_fd);
close(ctx->ipv6->nd_fd);
ctx->ipv6->nd_fd = -1;
}
len = recvmsg(ctx->nd_fd, &ctx->rcvhdr, 0);
if (len == -1) {
logger(dctx, LOG_ERR, "recvmsg: %m");
- eloop_event_delete(dctx->eloop, ctx->nd_fd, 0);
+ eloop_event_delete(dctx->eloop, ctx->nd_fd);
close(ctx->nd_fd);
ctx->nd_fd = -1;
return;