X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/96ffb2fe97c3e77879e7a4f6f7457397a18bf233..4b1f6ad3e7a5c7c28618e43e7539c9a937bf8521:/src/ae_kqueue.c?ds=sidebyside diff --git a/src/ae_kqueue.c b/src/ae_kqueue.c index 04c3536b..e91a254d 100644 --- a/src/ae_kqueue.c +++ b/src/ae_kqueue.c @@ -8,15 +8,24 @@ typedef struct aeApiState { int kqfd; - struct kevent events[AE_SETSIZE]; + struct kevent *events; } aeApiState; static int aeApiCreate(aeEventLoop *eventLoop) { aeApiState *state = zmalloc(sizeof(aeApiState)); if (!state) return -1; + state->events = zmalloc(sizeof(struct kevent)*eventLoop->setsize); + if (!state->events) { + zfree(state); + return -1; + } state->kqfd = kqueue(); - if (state->kqfd == -1) return -1; + if (state->kqfd == -1) { + zfree(state->events); + zfree(state); + return -1; + } eventLoop->apidata = state; return 0; @@ -26,6 +35,7 @@ static void aeApiFree(aeEventLoop *eventLoop) { aeApiState *state = eventLoop->apidata; close(state->kqfd); + zfree(state->events); zfree(state); } @@ -66,10 +76,12 @@ static int aeApiPoll(aeEventLoop *eventLoop, struct timeval *tvp) { struct timespec timeout; timeout.tv_sec = tvp->tv_sec; timeout.tv_nsec = tvp->tv_usec * 1000; - retval = kevent(state->kqfd, NULL, 0, state->events, AE_SETSIZE, &timeout); + retval = kevent(state->kqfd, NULL, 0, state->events, eventLoop->setsize, + &timeout); } else { - retval = kevent(state->kqfd, NULL, 0, state->events, AE_SETSIZE, NULL); - } + retval = kevent(state->kqfd, NULL, 0, state->events, eventLoop->setsize, + NULL); + } if (retval > 0) { int j;