#ifdef __APPLE__ /* Apple wants us to define this if we might ever pass more than
* FD_SETSIZE bits to select(). */ #define _DARWIN_UNLIMITED_SELECT #endif
/* Divide positive x by y, rounding up. */ #define DIV_ROUNDUP(x, y) (((x)+((y)-1))/(y))
/* How many bytes to allocate for N fds? */ #define SELECT_ALLOC_SIZE(n) \
(DIV_ROUNDUP(n, NFDBITS) * sizeof(fd_mask))
struct selectop { int event_fds; /* Highest fd in fd set */ int event_fdsz; int resize_out_sets;
fd_set *event_readset_in;
fd_set *event_writeset_in;
fd_set *event_readset_out;
fd_set *event_writeset_out;
};
staticvoid *select_init(struct event_base *); staticint select_add(struct event_base *, int, short old, short events, void*); staticint select_del(struct event_base *, int, short old, short events, void*); staticint select_dispatch(struct event_base *, struct timeval *); staticvoid select_dealloc(struct event_base *);
check_selectop(sop);
i = evutil_weakrand_range_(&base->weakrand_seed, nfds); for (j = 0; j < nfds; ++j) { if (++i >= nfds)
i = 0;
res = 0; if (FD_ISSET(i, sop->event_readset_out))
res |= EV_READ; if (FD_ISSET(i, sop->event_writeset_out))
res |= EV_WRITE;
if (res == 0) continue;
evmap_io_active_(base, i, res);
}
check_selectop(sop);
staticint
select_add(struct event_base *base, int fd, short old, short events, void *p)
{ struct selectop *sop = base->evbase;
(void) p;
EVUTIL_ASSERT((events & EV_SIGNAL) == 0);
check_selectop(sop); /* *Keeptrackofthehighestfd,sothatwecancalculatethesize *ofthefd_setsforselect(2)
*/ if (sop->event_fds < fd) { int fdsz = sop->event_fdsz;
if (fdsz < (int)sizeof(fd_mask))
fdsz = (int)sizeof(fd_mask);
/* In theory we should worry about overflow here. In *reality,though,thehighestfdonaunixysystemwill
* not overflow here. XXXX */ while (fdsz < (int) SELECT_ALLOC_SIZE(fd + 1))
fdsz *= 2;
if (fdsz != sop->event_fdsz) { if (select_resize(sop, fdsz)) {
check_selectop(sop); return (-1);
}
}
sop->event_fds = fd;
}
if (events & EV_READ)
FD_SET(fd, sop->event_readset_in); if (events & EV_WRITE)
FD_SET(fd, sop->event_writeset_in);
check_selectop(sop);
return (0);
}
/* *Nothingtobedonehere.
*/
staticint
select_del(struct event_base *base, int fd, short old, short events, void *p)
{ struct selectop *sop = base->evbase;
(void)p;
if (sop->event_fds < fd) {
check_selectop(sop); return (0);
}
if (events & EV_READ)
FD_CLR(fd, sop->event_readset_in);
if (events & EV_WRITE)
FD_CLR(fd, sop->event_writeset_in);
check_selectop(sop); return (0);
}
staticvoid
select_free_selectop(struct selectop *sop)
{ if (sop->event_readset_in)
mm_free(sop->event_readset_in); if (sop->event_writeset_in)
mm_free(sop->event_writeset_in); if (sop->event_readset_out)
mm_free(sop->event_readset_out); if (sop->event_writeset_out)
mm_free(sop->event_writeset_out);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.