aboutsummaryrefslogtreecommitdiff
path: root/examples/redis-unstable/src/ae_select.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/redis-unstable/src/ae_select.c')
-rw-r--r--examples/redis-unstable/src/ae_select.c90
1 files changed, 0 insertions, 90 deletions
diff --git a/examples/redis-unstable/src/ae_select.c b/examples/redis-unstable/src/ae_select.c
deleted file mode 100644
index 208cc32..0000000
--- a/examples/redis-unstable/src/ae_select.c
+++ /dev/null
@@ -1,90 +0,0 @@
1/* Select()-based ae.c module.
2 *
3 * Copyright (c) 2009-Present, Redis Ltd.
4 * All rights reserved.
5 *
6 * Licensed under your choice of (a) the Redis Source Available License 2.0
7 * (RSALv2); or (b) the Server Side Public License v1 (SSPLv1); or (c) the
8 * GNU Affero General Public License v3 (AGPLv3).
9 */
10
11
12#include <sys/select.h>
13#include <string.h>
14
15typedef struct aeApiState {
16 fd_set rfds, wfds;
17 /* We need to have a copy of the fd sets as it's not safe to reuse
18 * FD sets after select(). */
19 fd_set _rfds, _wfds;
20} aeApiState;
21
22static int aeApiCreate(aeEventLoop *eventLoop) {
23 aeApiState *state = zmalloc(sizeof(aeApiState));
24
25 if (!state) return -1;
26 FD_ZERO(&state->rfds);
27 FD_ZERO(&state->wfds);
28 eventLoop->apidata = state;
29 return 0;
30}
31
32static int aeApiResize(aeEventLoop *eventLoop, int setsize) {
33 AE_NOTUSED(eventLoop);
34 /* Just ensure we have enough room in the fd_set type. */
35 if (setsize >= FD_SETSIZE) return -1;
36 return 0;
37}
38
39static void aeApiFree(aeEventLoop *eventLoop) {
40 zfree(eventLoop->apidata);
41}
42
43static int aeApiAddEvent(aeEventLoop *eventLoop, int fd, int mask) {
44 aeApiState *state = eventLoop->apidata;
45
46 if (mask & AE_READABLE) FD_SET(fd,&state->rfds);
47 if (mask & AE_WRITABLE) FD_SET(fd,&state->wfds);
48 return 0;
49}
50
51static void aeApiDelEvent(aeEventLoop *eventLoop, int fd, int mask) {
52 aeApiState *state = eventLoop->apidata;
53
54 if (mask & AE_READABLE) FD_CLR(fd,&state->rfds);
55 if (mask & AE_WRITABLE) FD_CLR(fd,&state->wfds);
56}
57
58static int aeApiPoll(aeEventLoop *eventLoop, struct timeval *tvp) {
59 aeApiState *state = eventLoop->apidata;
60 int retval, j, numevents = 0;
61
62 memcpy(&state->_rfds,&state->rfds,sizeof(fd_set));
63 memcpy(&state->_wfds,&state->wfds,sizeof(fd_set));
64
65 retval = select(eventLoop->maxfd+1,
66 &state->_rfds,&state->_wfds,NULL,tvp);
67 if (retval > 0) {
68 for (j = 0; j <= eventLoop->maxfd; j++) {
69 int mask = 0;
70 aeFileEvent *fe = &eventLoop->events[j];
71
72 if (fe->mask == AE_NONE) continue;
73 if (fe->mask & AE_READABLE && FD_ISSET(j,&state->_rfds))
74 mask |= AE_READABLE;
75 if (fe->mask & AE_WRITABLE && FD_ISSET(j,&state->_wfds))
76 mask |= AE_WRITABLE;
77 eventLoop->fired[numevents].fd = j;
78 eventLoop->fired[numevents].mask = mask;
79 numevents++;
80 }
81 } else if (retval == -1 && errno != EINTR) {
82 panic("aeApiPoll: select, %s", strerror(errno));
83 }
84
85 return numevents;
86}
87
88static char *aeApiName(void) {
89 return "select";
90}