diff options
author | antirez <antirez@gmail.com> | 2013-06-28 16:39:49 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2013-06-28 16:39:49 +0200 |
commit | 8e2d082066e5b9892ead6cd30e8d3852d02fbc04 (patch) | |
tree | 1422465efe7dfb3cb8e4b78166c13800e99a72b9 /src/ae.c | |
parent | 3130670b978e0d4baa805016386e5ca56af08123 (diff) | |
download | redis-8e2d082066e5b9892ead6cd30e8d3852d02fbc04.tar.gz |
ae.c event loop: API to resize the fd set size on the run.
Diffstat (limited to 'src/ae.c')
-rw-r--r-- | src/ae.c | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -91,6 +91,36 @@ err: return NULL; } +/* Return the current set size. */ +int aeGetSetSize(aeEventLoop *eventLoop) { + return eventLoop->setsize; +} + +/* Resize the maximum set size of the event loop. + * If the requested set size is smaller than the current set size, but + * there is already a file descriptor in use that is >= the requested + * set size minus one, AE_ERR is returned and the operation is not + * performed at all. + * + * Otherwise AE_OK is returned and the operation is successful. */ +int aeResizeSetSize(aeEventLoop *eventLoop, int setsize) { + int i; + + if (setsize == eventLoop->setsize) return AE_OK; + if (eventLoop->maxfd >= setsize) return AE_ERR; + if (aeApiResize(eventLoop,setsize) == -1) return AE_ERR; + + eventLoop->events = zrealloc(eventLoop->events,sizeof(aeFileEvent)*setsize); + eventLoop->fired = zrealloc(eventLoop->fired,sizeof(aeFiredEvent)*setsize); + eventLoop->setsize = setsize; + + /* Make sure that if we created new slots, they are initialized with + * an AE_NONE mask. */ + for (i = eventLoop->maxfd+1; i < setsize; i++) + eventLoop->events[i].mask = AE_NONE; + return AE_OK; +} + void aeDeleteEventLoop(aeEventLoop *eventLoop) { aeApiFree(eventLoop); zfree(eventLoop->events); |