rendered paste bodystruct ev_ct *ev_ct_new(int maxfdhint, int type) {
unsigned i;
struct ev_ct *ct;
const struct ev_method *em;
int maxfd;
const char *method;
ev_gettime();
ct = (struct ev_ct *) calloc(1, sizeof(struct ev_ct));
if (!ct)
return errno = ENOMEM, (struct ev_ct*)0;
ct->qfd = -1;
i = 0;
if (maxfdhint <= 0)
maxfdhint = ev_fdlimit();
maxfdhint = ARR_ROUND(maxfdhint);
method = getenv("EV_METHOD");
if (method || !type)
type = 0xffff;
#ifdef ENOTSUP
errno = ENOTSUP;
#else
errno = ENOENT;
#endif
for(;;) {
em = &methods[i];
if ((em->type & type) && (!method || strcmp(method, em->name) == 0)) {
maxfd = em->maxfd && em->maxfd < maxfdhint ?
em->maxfd : maxfdhint;
if (em->init(ct, maxfd) == 0)
break;
}
if (++i < sizeof(methods)/sizeof(methods[0]))
continue;
free(ct);
return NULL;
}
ct->efd = (struct ev_fd *)calloc(maxfd, sizeof(struct ev_fd));
if (!ct->efd) {
if (ct->qfd >= 0) close(ct->qfd);
#if HAVE_POLL
if (ct->pfd) free(ct->pfd);
#endif
free(ct);
errno = ENOMEM;
return NULL;
}