Lines Matching defs:eh

60 	iu_eh_t	*eh = malloc(sizeof (iu_eh_t));
63 if (eh == NULL)
66 eh->iueh_pollfds = NULL;
67 eh->iueh_events = NULL;
68 eh->iueh_shutdown = NULL;
69 eh->iueh_num_fds = 0;
70 eh->iueh_stop = B_FALSE;
71 eh->iueh_reason = 0;
72 eh->iueh_shutdown_arg = NULL;
74 (void) sigemptyset(&eh->iueh_sig_regset);
76 eh->iueh_sig_info[sig].iues_pending = B_FALSE;
77 eh->iueh_sig_info[sig].iues_handler = NULL;
78 eh->iueh_sig_info[sig].iues_data = NULL;
81 return (eh);
89 * notes: it is assumed all events related to this eh have been unregistered
94 iu_eh_destroy(iu_eh_t *eh)
99 if (signal_to_eh[sig] == eh)
100 (void) iu_eh_unregister_signal(eh, sig, NULL);
102 free(eh->iueh_pollfds);
103 free(eh->iueh_events);
104 free(eh);
122 iu_stop_handling_events(iu_eh_t *eh, unsigned int reason,
125 eh->iueh_stop = B_TRUE;
126 eh->iueh_reason = reason;
127 eh->iueh_shutdown = shutdown;
128 eh->iueh_shutdown_arg = arg;
141 grow_fds(iu_eh_t *eh, int total_fds)
147 if (total_fds <= eh->iueh_num_fds)
150 new_pollfds = realloc(eh->iueh_pollfds,
155 eh->iueh_pollfds = new_pollfds;
157 new_events = realloc(eh->iueh_events,
172 for (i = eh->iueh_num_fds; i < total_fds; i++)
173 eh->iueh_pollfds[i].fd = -1;
175 eh->iueh_events = new_events;
176 eh->iueh_num_fds = total_fds;
199 iu_register_event(iu_eh_t *eh, int fd, short events, iu_eh_callback_t *callback,
202 if (eh->iueh_num_fds <= fd)
203 if (grow_fds(eh, fd + EH_FD_SLACK) == 0)
218 if (eh->iueh_pollfds[fd].fd != -1)
221 eh->iueh_pollfds[fd].fd = fd;
222 eh->iueh_pollfds[fd].events = events;
223 eh->iueh_events[fd].iuen_callback = callback;
224 eh->iueh_events[fd].iuen_arg = arg;
241 iu_unregister_event(iu_eh_t *eh, iu_event_id_t event_id, void **arg)
243 if (event_id < 0 || event_id >= eh->iueh_num_fds ||
244 eh->iueh_pollfds[event_id].fd == -1)
254 eh->iueh_pollfds[event_id].revents = 0;
255 eh->iueh_pollfds[event_id].fd = -1;
257 *arg = eh->iueh_events[event_id].iuen_arg;
272 iu_handle_events(iu_eh_t *eh, iu_tq_t *tq)
278 eh->iueh_stop = B_FALSE;
288 (void) sigprocmask(SIG_UNBLOCK, &eh->iueh_sig_regset, &oset);
289 n_lit = poll(eh->iueh_pollfds, eh->iueh_num_fds, timeout);
300 if (eh->iueh_sig_info[sig].iues_pending) {
301 eh->iueh_sig_info[sig].iues_pending =
303 eh->iueh_sig_info[sig].iues_handler(eh,
305 eh->iueh_sig_info[sig].iues_data);
309 if (eh->iueh_shutdown != NULL)
329 for (i = 0; i < eh->iueh_num_fds && n_lit > 0; i++) {
331 if (eh->iueh_pollfds[i].revents == 0)
341 if (eh->iueh_pollfds[i].revents & (POLLNVAL|POLLERR)) {
343 (void) iu_unregister_event(eh, i, NULL);
347 eh->iueh_events[i].iuen_callback(eh, i,
348 eh->iueh_pollfds[i].revents, i,
349 eh->iueh_events[i].iuen_arg);
352 } while (eh->iueh_stop == B_FALSE || (eh->iueh_shutdown != NULL &&
353 eh->iueh_shutdown(eh, eh->iueh_shutdown_arg) == B_FALSE));
355 return (eh->iueh_reason);
383 iu_eh_register_signal(iu_eh_t *eh, int sig, iu_eh_sighandler_t *handler,
401 eh->iueh_sig_info[sig].iues_data = data;
402 eh->iueh_sig_info[sig].iues_handler = handler;
403 signal_to_eh[sig] = eh;
405 (void) sigaddset(&eh->iueh_sig_regset, sig);
420 iu_eh_unregister_signal(iu_eh_t *eh, int sig, void **datap)
424 if (sig < 0 || sig >= NSIG || signal_to_eh[sig] != eh)
431 *datap = eh->iueh_sig_info[sig].iues_data;
437 eh->iueh_sig_info[sig].iues_data = NULL;
438 eh->iueh_sig_info[sig].iues_handler = NULL;
439 eh->iueh_sig_info[sig].iues_pending = B_FALSE;
442 (void) sigdelset(&eh->iueh_sig_regset, sig);