ev.h
static void ev_add_monitored(ev_context *ctx, int fd, int mask,
                             void (*callback)(ev_context *, void *),
                             void *ptr) {
    /*
     * TODO check for fd <= 1024 if using SELECT
     * That is because FD_SETSIZE is fixed to 1024, fd_set is an array of 32
     * i32 and each FD is represented by a bit so 32 x 32 = 1024 as hard limit
     */
    if (fd >= ctx->maxevents) {
        int i = ctx->maxevents;
        ctx->maxevents = fd;
        if (fd >= ctx->events_nr) {
            ctx->events_monitored =
                realloc(ctx->events_monitored, (fd + 1) * sizeof(struct ev));
            for (; i < ctx->maxevents; ++i)
                ctx->events_monitored[i].mask = EV_NONE;
        }
    }
    ctx->events_monitored[fd].fd = fd;
    ctx->events_monitored[fd].mask |= mask;
    if (mask & EV_READ) {
        ctx->events_monitored[fd].rdata = ptr;
        ctx->events_monitored[fd].rcallback = callback;
    }
    if (mask & EV_WRITE) {
        ctx->events_monitored[fd].wdata = ptr;
        ctx->events_monitored[fd].wcallback = callback;
    }
}
/*
 * Auxiliary function, update FD, mask and data in monitored events array.
 * Monitored events are the same number as the maximum FD registered in the
 * context.
 */
Auxiliary function, update FD, mask and data in monitored events array.
Monitored events are the same number as the maximum FD registered in the
context.
Auxiliary function update FD mask and data in monitored events array . Monitored events are the same number as the maximum FD registered in the context .
static void ev_add_monitored(ev_context *ctx, int fd, int mask,
                             void (*callback)(ev_context *, void *),
                             void *ptr) {
    if (fd >= ctx->maxevents) {
        int i = ctx->maxevents;
        ctx->maxevents = fd;
        if (fd >= ctx->events_nr) {
            ctx->events_monitored =
                realloc(ctx->events_monitored, (fd + 1) * sizeof(struct ev));
            for (; i < ctx->maxevents; ++i)
                ctx->events_monitored[i].mask = EV_NONE;
        }
    }
    ctx->events_monitored[fd].fd = fd;
    ctx->events_monitored[fd].mask |= mask;
    if (mask & EV_READ) {
        ctx->events_monitored[fd].rdata = ptr;
        ctx->events_monitored[fd].rcallback = callback;
    }
    if (mask & EV_WRITE) {
        ctx->events_monitored[fd].wdata = ptr;
        ctx->events_monitored[fd].wcallback = callback;
    }
}
static void ev_add_monitored ( ev_context * ctx , int fd , int mask , void ( * callback ) ( ev_context * , void * ) , void * ptr ) { if ( fd >= ctx -> maxevents ) { int i = ctx -> maxevents ; ctx -> maxevents = fd ; if ( fd >= ctx -> events_nr ) { ctx -> events_monitored = realloc ( ctx -> events_monitored , ( fd + 1 ) * sizeof ( struct ev ) ) ; for ( ; i < ctx -> maxevents ; ++ i ) ctx -> events_monitored [ i ] . mask = EV_NONE ; } } ctx -> events_monitored [ fd ] . fd = fd ; ctx -> events_monitored [ fd ] . mask |= mask ; if ( mask & EV_READ ) { ctx -> events_monitored [ fd ] . rdata = ptr ; ctx -> events_monitored [ fd ] . rcallback = callback ; } if ( mask & EV_WRITE ) { ctx -> events_monitored [ fd ] . wdata = ptr ; ctx -> events_monitored [ fd ] . wcallback = callback ; } }
Auxiliary function, update FD, mask and data in monitored events array.
Auxiliary function update FD mask and data in monitored events array .
/*
     * TODO check for fd <= 1024 if using SELECT
     * That is because FD_SETSIZE is fixed to 1024, fd_set is an array of 32
     * i32 and each FD is represented by a bit so 32 x 32 = 1024 as hard limit
     */