Beispiel #1
0
static int
create_kqueue(poller *p){
	if(p->pfds_available <= 0){
		bitch("Poller's pfds weren't initialized\n");
		return -1;
	}
	p->ksize = p->pfds_available;
	p->csize = 2 * p->pfds_available;
	if((p->kv = Malloc("kqueue vector",sizeof(*p->kv) * p->ksize)) == NULL){
		return -1;
	}
	if((p->cv = Malloc("kchange vector",sizeof(*p->cv) * p->csize)) == NULL){
		Free(p->kv);
		return -1;
	}
	if((p->kq = kqueue()) < 0){
		Free(p->kv);
		Free(p->cv);
		return -1;
	}
	p->kchanges = 0;
	if(enqueue_kqueue_change(p,POLLERSIGNAL,EVFILT_SIGNAL,EV_ADD,0,0,NULL)){
		destroy_kqueue(p);
		return -1;
	}
	if(enqueue_kqueue_change(p,SIGCHLD,EVFILT_SIGNAL,EV_ADD,0,0,NULL)){
		destroy_kqueue(p);
		return -1;
	}
	return 0;
}
Beispiel #2
0
/*!
 * \brief destroys everything init_io_wait allocated
 * \param h IO handle
 */
void destroy_io_wait(io_wait_h* h)
{
	switch(h->poll_method){
#ifdef HAVE_EPOLL
		case POLL_EPOLL_LT:
		case POLL_EPOLL_ET:
			destroy_epoll(h);
			if (h->ep_array){
				local_free(h->ep_array);
				h->ep_array=0;
			}
		break;
#endif
#ifdef HAVE_KQUEUE
		case POLL_KQUEUE:
			destroy_kqueue(h);
			if (h->kq_array){
				local_free(h->kq_array);
				h->kq_array=0;
			}
			if (h->kq_changes){
				local_free(h->kq_changes);
				h->kq_changes=0;
			}
			break;
#endif
#ifdef HAVE_SIGIO_RT
		case POLL_SIGIO_RT:
			destroy_sigio(h);
			break;
#endif
#ifdef HAVE_DEVPOLL
		case POLL_DEVPOLL:
			destroy_devpoll(h);
			if (h->dp_changes){
				local_free(h->dp_changes);
				h->dp_changes=0;
			}
			break;
#endif
		default: /*do  nothing*/
			;
	}
		if (h->fd_array){
			local_free(h->fd_array);
			h->fd_array=0;
		}
		if (h->fd_hash){
			local_free(h->fd_hash);
			h->fd_hash=0;
		}
		if (h->prio_idx){
			local_free(h->prio_idx);
			h->prio_idx=0;
		}

}