X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/214d880b815242fa419aa3a39411d42025566521..978c2c944cb540827ba53ceb2301e4bd460d9591:/ae_epoll.c diff --git a/ae_epoll.c b/ae_epoll.c index 8fb5d4c3..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,15 @@ 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; @@ -50,7 +52,6 @@ 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) { @@ -78,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"; +}