MCPcopy Create free account
hub / github.com/acl-dev/acl / test_disable_enable

Function test_disable_enable

lib_fiber/samples-c/test/kqueue_hook/main.c:192–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

190}
191
192static void test_disable_enable(int fd_read, int fd_write)
193{
194 int kqfd;
195 struct kevent changes[1];
196 struct kevent events[2];
197 int n;
198 char buf[8];
199
200 kqfd = kqueue();
201 if (kqfd < 0) {
202 fail("kqueue() failed (disable/enable)");
203 return;
204 }
205
206 EV_SET(&changes[0], fd_read, EVFILT_READ, EV_ADD | EV_DISABLE,
207 0, 0, NULL);
208 if (kevent(kqfd, changes, 1, NULL, 0, NULL) < 0) {
209 fail("kevent add disable failed");
210 return;
211 }
212
213 if (write(fd_write, "d", 1) != 1) {
214 fail("write failed (disable)");
215 return;
216 }
217
218 memset(events, 0, sizeof(events));
219 n = kevent(kqfd, NULL, 0, events, 2, &(struct timespec){0, 0});
220 if (n != 0) {
221 fail("disable: event should be disabled");
222 return;
223 }
224
225 EV_SET(&changes[0], fd_read, EVFILT_READ, EV_ENABLE, 0, 0, NULL);
226 if (kevent(kqfd, changes, 1, NULL, 0, NULL) < 0) {
227 fail("enable failed");
228 return;
229 }
230
231 memset(events, 0, sizeof(events));
232 n = kevent(kqfd, NULL, 0, events, 2, &(struct timespec){1, 0});
233 if (n != 1 || !expect_filter(events, n, EVFILT_READ)) {
234 fail("enable: read event missing");
235 return;
236 }
237
238 (void) read(fd_read, buf, sizeof(buf));
239 close(kqfd);
240}
241
242static void test_delete(int fd_read, int fd_write)
243{

Callers

nothing calls this directly

Calls 7

kqueueFunction · 0.85
failFunction · 0.85
expect_filterFunction · 0.85
keventClass · 0.70
writeFunction · 0.50
readFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…