kq_dispatch(void *arg, struct timeval *tv)
kq_dispatch(struct event_base *base, void *arg, struct timeval *tv)
kq_dispatch(void *arg, struct timeval *tv){	struct kqop *kqop = arg;	struct kevent *changes = kqop->changes;	struct kevent *events = kqop->events;	struct event *ev;	struct timespec ts;	int i, res;	TIMEVAL_TO_TIMESPEC(tv, &ts);	res = kevent(kqop->kq, changes, kqop->nchanges,	    events, kqop->nevents, &ts);	kqop->nchanges = 0;	if (res == -1) {		if (errno != EINTR) {			log_error("kevent");			return (-1);		}		return (0);	}	LOG_DBG((LOG_MISC, 80, "%s: kevent reports %d", __func__, res));	for (i = 0; i < res; i++) {		int which = 0;		if (events[i].flags & EV_ERROR) {			/* 			 * Error messages that can happen, when a delete fails.			 *   EBADF happens when the file discriptor has been			 *   closed,			 *   ENOENT when the file discriptor was closed and			 *   then reopened.			 * An error is also indicated when a callback deletes			 * an event we are still processing.  In that case			 * the data field is set to ENOENT.			 */			if (events[i].data == EBADF ||			    events[i].data == ENOENT)				continue;			return (-1);		}		ev = (struct event *)events[i].udata;		if (events[i].filter == EVFILT_READ) {			which |= EV_READ;		} else if (events[i].filter == EVFILT_WRITE) {			which |= EV_WRITE;		} else if (events[i].filter == EVFILT_SIGNAL) {			which |= EV_SIGNAL;		}		if (!which)			continue;		if (!(ev->ev_events & EV_PERSIST)) {			ev->ev_flags &= ~EVLIST_X_KQINKERNEL;			event_del(ev);		}		event_active(ev, which,		    ev->ev_events & EV_SIGNAL ? events[i].data : 1);	}	return (0);}