/* Iterate through all the event lists (such as connect_events, read_events, * timer_events, etc) and take action for those that have completed (due to * timeout, i/o, etc) */ void iterate_through_event_lists(mspool *nsp, int evcount) { int n; struct kqueue_engine_info *kinfo = (struct kqueue_engine_info *)nsp->engine_data; msiod *nsi; for (n = 0; n < evcount; n++) { struct kevent *kev = &kinfo->events[n]; nsi = (msiod *)kev->udata; /* process all the pending events for this IOD */ process_iod_events(nsp, nsi, get_evmask(nsi, kev)); IOD_PROPSET(nsi, IOD_PROCESSED); } for (n = 0; n < evcount; n++) { struct kevent *kev = &kinfo->events[n]; nsi = (msiod *)kev->udata; if (nsi->state == NSIOD_STATE_DELETED) { if (IOD_PROPGET(nsi, IOD_PROCESSED)) { IOD_PROPCLR(nsi, IOD_PROCESSED); gh_list_remove(&nsp->active_iods, &nsi->nodeq); gh_list_prepend(&nsp->free_iods, &nsi->nodeq); } } } /* iterate through timers and expired events */ process_expired_events(nsp); }
int select_iod_unregister(mspool *nsp, msiod *iod) { struct select_engine_info *sinfo = (struct select_engine_info *)nsp->engine_data; iod->watched_events = EV_NONE; /* some IODs can be unregistered here if they're associated to an event that was * immediately completed */ if (IOD_PROPGET(iod, IOD_REGISTERED)) { #if HAVE_PCAP if (iod->pcap) { int sd = ((mspcap *)iod->pcap)->pcap_desc; if (sd >= 0) { CHECKED_FD_CLR(sd, &sinfo->fds_master_r); CHECKED_FD_CLR(sd, &sinfo->fds_results_r); } } else #endif { CHECKED_FD_CLR(iod->sd, &sinfo->fds_master_r); CHECKED_FD_CLR(iod->sd, &sinfo->fds_master_w); CHECKED_FD_CLR(iod->sd, &sinfo->fds_master_x); CHECKED_FD_CLR(iod->sd, &sinfo->fds_results_r); CHECKED_FD_CLR(iod->sd, &sinfo->fds_results_w); CHECKED_FD_CLR(iod->sd, &sinfo->fds_results_x); } if (sinfo->max_sd == iod->sd) sinfo->max_sd--; IOD_PROPCLR(iod, IOD_REGISTERED); } return 1; }
/* Iterate through all the event lists (such as connect_events, read_events, * timer_events, etc) and take action for those that have completed (due to * timeout, i/o, etc) */ void iterate_through_event_lists(mspool *nsp, int evcount) { int n; struct kqueue_engine_info *kinfo = (struct kqueue_engine_info *)nsp->engine_data; gh_list_elem *current, *next, *last, *timer_last; msevent *nse; msiod *nsi; /* Clear it -- We will find the next event as we go through the list */ nsp->next_ev.tv_sec = 0; last = GH_LIST_LAST_ELEM(&nsp->active_iods); timer_last = GH_LIST_LAST_ELEM(&nsp->timer_events); for (n = 0; n < evcount; n++) { struct kevent *kev = &kinfo->events[n]; nsi = (msiod *)kev->udata; /* process all the pending events for this IOD */ process_iod_events(nsp, nsi, get_evmask(nsi, kev)); IOD_PROPSET(nsi, IOD_PROCESSED); } current = GH_LIST_FIRST_ELEM(&nsp->active_iods); /* cull timeouts amongst the non active IODs */ while (current != NULL && GH_LIST_ELEM_PREV(current) != last) { msiod *nsi = (msiod *)GH_LIST_ELEM_DATA(current); if (IOD_PROPGET(nsi, IOD_PROCESSED)) IOD_PROPCLR(nsi, IOD_PROCESSED); else if (nsi->state != NSIOD_STATE_DELETED && nsi->events_pending) process_iod_events(nsp, nsi, EV_NONE); next = GH_LIST_ELEM_NEXT(current); if (nsi->state == NSIOD_STATE_DELETED) { gh_list_remove_elem(&nsp->active_iods, current); gh_list_prepend(&nsp->free_iods, nsi); } current = next; } /* iterate through timers */ for (current = GH_LIST_FIRST_ELEM(&nsp->timer_events); current != NULL && GH_LIST_ELEM_PREV(current) != timer_last; current = next) { nse = (msevent *)GH_LIST_ELEM_DATA(current); process_event(nsp, &nsp->timer_events, nse, EV_NONE); next = GH_LIST_ELEM_NEXT(current); if (nse->event_done) gh_list_remove_elem(&nsp->timer_events, current); } }
int kqueue_iod_unregister(mspool *nsp, msiod *iod) { struct kqueue_engine_info *kinfo = (struct kqueue_engine_info *)nsp->engine_data; /* some IODs can be unregistered here if they're associated to an event that was * immediately completed */ if (IOD_PROPGET(iod, IOD_REGISTERED)) { kqueue_iod_modify(nsp, iod, EV_NONE, EV_READ|EV_WRITE); IOD_PROPCLR(iod, IOD_REGISTERED); if (nsi_getsd(iod) == kinfo->maxfd) kinfo->maxfd--; } iod->watched_events = EV_NONE; return 1; }
int epoll_iod_unregister(mspool *nsp, msiod *iod) { iod->watched_events = EV_NONE; /* some IODs can be unregistered here if they're associated to an event that was * immediately completed */ if (IOD_PROPGET(iod, IOD_REGISTERED)) { struct epoll_engine_info *einfo = (struct epoll_engine_info *)nsp->engine_data; int sd; sd = nsi_getsd(iod); epoll_ctl(einfo->epfd, EPOLL_CTL_DEL, sd, NULL); IOD_PROPCLR(iod, IOD_REGISTERED); } return 1; }
int poll_iod_unregister(struct npool *nsp, struct niod *iod) { iod->watched_events = EV_NONE; /* some IODs can be unregistered here if they're associated to an event that was * immediately completed */ if (IOD_PROPGET(iod, IOD_REGISTERED)) { struct poll_engine_info *pinfo = (struct poll_engine_info *)nsp->engine_data; int sd; sd = nsi_getsd(iod); pinfo->events[sd].fd = -1; pinfo->events[sd].events = 0; pinfo->events[sd].revents = 0; if (pinfo->max_fd == sd) lower_max_fd(pinfo); IOD_PROPCLR(iod, IOD_REGISTERED); } return 1; }