Пример #1
0
int
sel_select(selector_t      *sel,
	   sel_send_sig_cb send_sig,
	   long            thread_id,
	   void            *cb_data,
	   struct timeval  *timeout)
{
    int             err;
    struct timeval  loc_timeout;
    sel_wait_list_t wait_entry;

    if (sel->have_timer_lock)
	sel->os_hnd->lock(sel->os_hnd, sel->timer_lock);
    process_timers(sel, (struct timeval *)(&loc_timeout));
    if (timeout) { 
	if (cmp_timeval((struct timeval *)(&loc_timeout), timeout) >= 0)
	    memcpy(&loc_timeout, timeout, sizeof(loc_timeout));
    }
    add_sel_wait_list(sel, &wait_entry, send_sig, cb_data, thread_id,
		      &loc_timeout);
    if (sel->have_timer_lock)
	sel->os_hnd->unlock(sel->os_hnd, sel->timer_lock);

    err = process_fds(sel, send_sig, thread_id, cb_data, &loc_timeout);

    if (sel->have_timer_lock)
	sel->os_hnd->lock(sel->os_hnd, sel->timer_lock);
    remove_sel_wait_list(sel, &wait_entry);
    if (sel->have_timer_lock)
	sel->os_hnd->unlock(sel->os_hnd, sel->timer_lock);
    return err;
}
Пример #2
0
int				net_fdset_process(t_net_fdset *set, cb_net_fdset check)
{
	fd_set		fdsets[2];
	int			res;

	if (!set || !check)
		return (-1);
	init(set, fdsets, check);
	res = select(set->fd_max, &fdsets[0], &fdsets[1], 0, 0);
	if (res == -1)
	{
		dprintf(2, "select(): %s\n", strerror(errno));
		return (-1);
	}
	if (process_fds(set, res, fdsets) == -1)
		return (-1);
	return (0);
}
Пример #3
0
/* The main loop for the program.  This will select on the various
   sets, then scan for any available I/O to process.  It also monitors
   the time and call the timeout handlers periodically. */
int
sel_select_loop(selector_t      *sel,
		sel_send_sig_cb send_sig,
		long            thread_id,
		void            *cb_data)
{
    int             err;
    sel_wait_list_t wait_entry;
    struct timeval  loc_timeout;

    for (;;) {
	if (sel->have_timer_lock)
	    sel->os_hnd->lock(sel->os_hnd, sel->timer_lock);
    	process_timers(sel, &loc_timeout);
	add_sel_wait_list(sel, &wait_entry, send_sig, cb_data, thread_id,
			  &loc_timeout);
	if (sel->have_timer_lock)
	    sel->os_hnd->unlock(sel->os_hnd, sel->timer_lock);
	
	err = process_fds(sel, send_sig, thread_id, cb_data, &loc_timeout);

	if (sel->have_timer_lock)
	    sel->os_hnd->lock(sel->os_hnd, sel->timer_lock);
	remove_sel_wait_list(sel, &wait_entry);
	if (sel->have_timer_lock)
	    sel->os_hnd->unlock(sel->os_hnd, sel->timer_lock);

    	if ((err < 0) && (errno != EINTR)) {
	    err = errno;
	    /* An error occurred. */
	    /* An error is bad, we need to abort. */
	    syslog(LOG_ERR, "select_loop() - select: %m");
	    return err;
	}
    }
}