MCPcopy Create free account
hub / github.com/F-Stack/f-stack / aeApiPoll

Function aeApiPoll

app/redis-6.2.6/src/ae_ff_kqueue.c:134–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134static int aeApiPoll(aeEventLoop *eventLoop, struct timeval *tvp) {
135 aeApiState *state = eventLoop->apidata;
136 int retval, numevents = 0;
137
138 if (tvp != NULL) {
139 struct timespec timeout;
140 timeout.tv_sec = tvp->tv_sec;
141 timeout.tv_nsec = tvp->tv_usec * 1000;
142 retval = ff_kevent(state->kqfd, NULL, 0, state->events, eventLoop->setsize,
143 &timeout);
144 } else {
145 retval = ff_kevent(state->kqfd, NULL, 0, state->events, eventLoop->setsize,
146 NULL);
147 }
148
149 if (retval > 0) {
150 int j;
151
152 /* Normally we execute the read event first and then the write event.
153 * When the barrier is set, we will do it reverse.
154 *
155 * However, under kqueue, read and write events would be separate
156 * events, which would make it impossible to control the order of
157 * reads and writes. So we store the event's mask we've got and merge
158 * the same fd events later. */
159 for (j = 0; j < retval; j++) {
160 struct kevent *e = state->events+j;
161 int fd = e->ident;
162 int mask = 0;
163
164 if (e->filter == EVFILT_READ) mask = AE_READABLE;
165 else if (e->filter == EVFILT_WRITE) mask = AE_WRITABLE;
166 addEventMask(state->eventsMask, fd, mask);
167 }
168
169 /* Re-traversal to merge read and write events, and set the fd's mask to
170 * 0 so that events are not added again when the fd is encountered again. */
171 numevents = 0;
172 for (j = 0; j < retval; j++) {
173 struct kevent *e = state->events+j;
174 int fd = e->ident;
175 int mask = getEventMask(state->eventsMask, fd);
176
177 if (mask) {
178 eventLoop->fired[numevents].fd = fd;
179 eventLoop->fired[numevents].mask = mask;
180 resetEventMask(state->eventsMask, fd);
181 numevents++;
182 }
183 }
184 }
185 return numevents;
186}
187
188static char *aeApiName(void) {
189 return "ff_kqueue";

Callers

nothing calls this directly

Calls 4

ff_keventFunction · 0.85
addEventMaskFunction · 0.70
getEventMaskFunction · 0.70
resetEventMaskFunction · 0.70

Tested by

no test coverage detected