X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/64f36a5836c8c375247ca0623712a35f80c6cfb2..18b6cb7643f23c3c3d8e44dc4584167fb2b32b58:/ae_epoll.c diff --git a/ae_epoll.c b/ae_epoll.c index b63b74b5..d48977b6 100644 --- a/ae_epoll.c +++ b/ae_epoll.c @@ -1,5 +1,5 @@ /* Linux epoll(2) based ae.c module - * Copyright (C) 2009 Salvatore Sanfilippo - antirez@gmail.com + * Copyright (C) 2009-2010 Salvatore Sanfilippo - antirez@gmail.com * Released under the BSD license. See the COPYING file for more info. */ #include @@ -29,13 +29,16 @@ static void aeApiFree(aeEventLoop *eventLoop) { static int aeApiAddEvent(aeEventLoop *eventLoop, int fd, int mask) { aeApiState *state = eventLoop->apidata; struct epoll_event ee; + /* If the fd was already monitored for some event, we need a MOD + * operation. Otherwise we need an ADD operation. */ int op = eventLoop->events[fd].mask == AE_NONE ? EPOLL_CTL_ADD : EPOLL_CTL_MOD; ee.events = 0; + mask |= eventLoop->events[fd].mask; /* Merge old events */ if (mask & AE_READABLE) ee.events |= EPOLLIN; if (mask & AE_WRITABLE) ee.events |= EPOLLOUT; - if (mask & AE_EXCEPTION) ee.events |= EPOLLPRI; + ee.data.u64 = 0; /* avoid valgrind warning */ ee.data.fd = fd; if (epoll_ctl(state->epfd,op,fd,&ee) == -1) return -1; return 0; @@ -49,7 +52,7 @@ static void aeApiDelEvent(aeEventLoop *eventLoop, int fd, int delmask) { ee.events = 0; if (mask & AE_READABLE) ee.events |= EPOLLIN; if (mask & AE_WRITABLE) ee.events |= EPOLLOUT; - if (mask & AE_EXCEPTION) ee.events |= EPOLLPRI; + ee.data.u64 = 0; /* avoid valgrind warning */ ee.data.fd = fd; if (mask != AE_NONE) { epoll_ctl(state->epfd,EPOLL_CTL_MOD,fd,&ee); @@ -76,10 +79,13 @@ static int aeApiPoll(aeEventLoop *eventLoop, struct timeval *tvp) { if (e->events & EPOLLIN) mask |= AE_READABLE; if (e->events & EPOLLOUT) mask |= AE_WRITABLE; - if (e->events & EPOLLPRI) mask |= AE_EXCEPTION; eventLoop->fired[j].fd = e->data.fd; eventLoop->fired[j].mask = mask; } } return numevents; } + +static char *aeApiName(void) { + return "epoll"; +}