void update_first_events(msevent *nse) { switch (get_event_id_type(nse->id)) { case NSE_TYPE_CONNECT: case NSE_TYPE_CONNECT_SSL: first_ev_next(nse, &nse->iod->first_connect, 0); break; case NSE_TYPE_READ: first_ev_next(nse, &nse->iod->first_read, 0); break; case NSE_TYPE_WRITE: first_ev_next(nse, &nse->iod->first_write, 0); break; #if HAVE_PCAP case NSE_TYPE_PCAP_READ: first_ev_next(nse, &nse->iod->first_read, 0); first_ev_next(nse, &nse->iod->first_pcap_read, 1); break; #endif case NSE_TYPE_TIMER: /* nothing to do */ break; default: fatal("Bogus event type in update_first_events"); break; } }
/* Cancel an event (such as a timer or read request). If notify is nonzero, the * requester will be sent an event CANCELLED status back to the given handler. * But in some cases there is no need to do this (like if the function deleting * it is the one which created it), in which case 0 can be passed to skip the * step. This function returns zero if the event is not found, nonzero * otherwise. */ int nsock_event_cancel(nsock_pool ms_pool, nsock_event_id id, int notify) { mspool *nsp = (mspool *)ms_pool; enum nse_type type; unsigned int i; gh_list_t *event_list = NULL, *event_list2 = NULL; gh_lnode_t *current, *next; msevent *nse = NULL; assert(nsp); type = get_event_id_type(id); nsock_log_info(nsp, "Event #%li (type %s) cancelled", id, nse_type2str(type)); /* First we figure out what list it is in */ switch (type) { case NSE_TYPE_CONNECT: case NSE_TYPE_CONNECT_SSL: event_list = &nsp->connect_events; break; case NSE_TYPE_READ: event_list = &nsp->read_events; break; case NSE_TYPE_WRITE: event_list = &nsp->write_events; break; case NSE_TYPE_TIMER: for (i = 0; i < gh_heap_count(&nsp->expirables); i++) { gh_hnode_t *hnode; hnode = gh_heap_find(&nsp->expirables, i); nse = container_of(hnode, msevent, expire); if (nse->id == id) return msevent_cancel(nsp, nse, NULL, NULL, notify); } return 0; #if HAVE_PCAP case NSE_TYPE_PCAP_READ: event_list = &nsp->read_events; event_list2 = &nsp->pcap_read_events; break; #endif default: fatal("Bogus event type in nsock_event_cancel"); break; } /* Now we try to find the event in the list */ for (current = gh_list_first_elem(event_list); current != NULL; current = next) { next = gh_lnode_next(current); nse = lnode_msevent(current); if (nse->id == id) break; } if (current == NULL && event_list2) { event_list = event_list2; for (current = gh_list_first_elem(event_list); current != NULL; current = next) { next = gh_lnode_next(current); nse = lnode_msevent2(current); if (nse->id == id) break; } } if (current == NULL) return 0; return msevent_cancel(nsp, nse, event_list, current, notify); }
/* Cancel an event (such as a timer or read request). If notify is nonzero, the * requester will be sent an event CANCELLED status back to the given handler. * But in some cases there is no need to do this (like if the function deleting * it is the one which created it), in which case 0 can be passed to skip the * step. This function returns zero if the event is not found, nonzero * otherwise. */ int nsock_event_cancel(nsock_pool ms_pool, nsock_event_id id, int notify) { mspool *nsp = (mspool *)ms_pool; enum nse_type type; gh_list *event_list = NULL, *event_list2 = NULL; gh_list_elem *current, *next; msevent *nse = NULL; assert(nsp); type = get_event_id_type(id); nsock_log_info(nsp, "Event #%li (type %s) cancelled", id, nse_type2str(type)); /* First we figure out what list it is in */ switch(type) { case NSE_TYPE_CONNECT: event_list = &nsp->connect_events; break; case NSE_TYPE_READ: event_list = &nsp->read_events; break; case NSE_TYPE_WRITE: event_list = &nsp->write_events; break; case NSE_TYPE_TIMER: event_list = &nsp->timer_events; break; #if HAVE_PCAP case NSE_TYPE_PCAP_READ: event_list = &nsp->read_events; event_list2 = &nsp->pcap_read_events; break; #endif default: fatal("Bogus event type in nsock_event_cancel"); break; } /* Now we try to find the event in the list */ for (current = GH_LIST_FIRST_ELEM(event_list); current != NULL; current = next) { next = GH_LIST_ELEM_NEXT(current); nse = (msevent *)GH_LIST_ELEM_DATA(current); if (nse->id == id) break; } if (current == NULL && event_list2){ event_list = event_list2; for (current = GH_LIST_FIRST_ELEM(event_list); current != NULL; current = next) { next = GH_LIST_ELEM_NEXT(current); nse = (msevent *)GH_LIST_ELEM_DATA(current); if (nse->id == id) break; } } if (current == NULL) return 0; return msevent_cancel(nsp, nse, event_list, current, notify); }