select.c
int
select_recalc(void *arg, int max)
{
	struct selectop *sop = arg;
	fd_set *readset, *writeset;
	struct event *ev;
	int fdsz;

	if (sop->event_fds < max)
		sop->event_fds = max;

	if (!sop->event_fds) {
		TAILQ_FOREACH(ev, &eventqueue, ev_next)
			if (ev->ev_fd > sop->event_fds)
				sop->event_fds = ev->ev_fd;
	}

	fdsz = howmany(sop->event_fds + 1, NFDBITS) * sizeof(fd_mask);
	if (fdsz > sop->event_fdsz) {
		if ((readset = realloc(sop->event_readset, fdsz)) == NULL) {
			log_error("malloc");
			return (-1);
		}

		if ((writeset = realloc(sop->event_writeset, fdsz)) == NULL) {
			log_error("malloc");
			free(readset);
			return (-1);
		}

		memset(readset + sop->event_fdsz, 0, fdsz - sop->event_fdsz);
		memset(writeset + sop->event_fdsz, 0, fdsz - sop->event_fdsz);

		sop->event_readset = readset;
		sop->event_writeset = writeset;
		sop->event_fdsz = fdsz;
	}

	return (0);
}
/*
 * Called with the highest fd that we know about.  If it is 0, completely
 * recalculate everything.
 */
Called with the highest fd that we know about.  If it is 0, completely
recalculate everything.
Called with the highest fd that we know about . If it is 0 completely recalculate everything .
int
select_recalc(void *arg, int max)
{
	struct selectop *sop = arg;
	fd_set *readset, *writeset;
	struct event *ev;
	int fdsz;
	if (sop->event_fds < max)
		sop->event_fds = max;
	if (!sop->event_fds) {
		TAILQ_FOREACH(ev, &eventqueue, ev_next)
			if (ev->ev_fd > sop->event_fds)
				sop->event_fds = ev->ev_fd;
	}
	fdsz = howmany(sop->event_fds + 1, NFDBITS) * sizeof(fd_mask);
	if (fdsz > sop->event_fdsz) {
		if ((readset = realloc(sop->event_readset, fdsz)) == NULL) {
			log_error("malloc");
			return (-1);
		}
		if ((writeset = realloc(sop->event_writeset, fdsz)) == NULL) {
			log_error("malloc");
			free(readset);
			return (-1);
		}
		memset(readset + sop->event_fdsz, 0, fdsz - sop->event_fdsz);
		memset(writeset + sop->event_fdsz, 0, fdsz - sop->event_fdsz);
		sop->event_readset = readset;
		sop->event_writeset = writeset;
		sop->event_fdsz = fdsz;
	}
	return (0);
}
int select_recalc ( void * arg , int max ) { struct selectop * sop = arg ; fd_set * readset , * writeset ; struct event * ev ; int fdsz ; if ( sop -> event_fds < max ) sop -> event_fds = max ; if ( ! sop -> event_fds ) { TAILQ_FOREACH ( ev , & eventqueue , ev_next ) if ( ev -> ev_fd > sop -> event_fds ) sop -> event_fds = ev -> ev_fd ; } fdsz = howmany ( sop -> event_fds + 1 , NFDBITS ) * sizeof ( fd_mask ) ; if ( fdsz > sop -> event_fdsz ) { if ( ( readset = realloc ( sop -> event_readset , fdsz ) ) == NULL ) { log_error ( " " ) ; return ( -1 ) ; } if ( ( writeset = realloc ( sop -> event_writeset , fdsz ) ) == NULL ) { log_error ( " " ) ; free ( readset ) ; return ( -1 ) ; } memset ( readset + sop -> event_fdsz , 0 , fdsz - sop -> event_fdsz ) ; memset ( writeset + sop -> event_fdsz , 0 , fdsz - sop -> event_fdsz ) ; sop -> event_readset = readset ; sop -> event_writeset = writeset ; sop -> event_fdsz = fdsz ; } return ( 0 ) ; }
Called with the highest fd that we know about.
Called with the highest fd that we know about .