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

Function kqueue

lib_fiber/c/src/hook/kqueue.c:369–409  ·  view source on GitHub ↗

Hook the system API to create one kqueue fd.

Source from the content-addressed store, hash-verified

367
368// Hook the system API to create one kqueue fd.
369int kqueue(void)
370{
371 EVENT *ev;
372 KQUEUE *kq;
373 int sys_kqfd, kqfd;
374
375 if (sys_kqueue == NULL) {
376 hook_once();
377 }
378
379 if (!var_hook_sys_api) {
380 return sys_kqueue ? (*sys_kqueue)() : -1;
381 }
382
383 ev = fiber_io_event();
384 assert(ev);
385
386 // Get the current thread's kqueue fd.
387 sys_kqfd = (int) event_handle(ev);
388 if (sys_kqfd < 0) {
389 msg_info("%s(%d), %s: no event_handle %d",
390 __FILE__, __LINE__, __FUNCTION__, sys_kqfd);
391 }
392
393 // Duplicate sys_kqfd and return a new fd to the caller.
394 kqfd = sys_kqfd >= 0 ? dup(sys_kqfd) : socket(AF_INET, SOCK_STREAM, 0);
395 if (kqfd < 0) {
396 msg_error("%s(%d): create fd error: %s",
397 __FILE__, __LINE__, last_serror());
398 return -1;
399 }
400
401 kq = kqueue_alloc(kqfd);
402 if (kq == NULL) {
403 msg_error("%s(%d): can't alloc KQUEUE for kqfd=%d",
404 __FUNCTION__, __LINE__, kqfd);
405 return -1;
406 }
407
408 return kq->kqfd;
409}
410
411// Event callback for readable fd in kqueue hook mode.
412static void read_callback(EVENT *ev, FILE_EVENT *fe)

Callers 11

test_dual_read_writeFunction · 0.85
test_oneshotFunction · 0.85
test_disable_enableFunction · 0.85
test_deleteFunction · 0.85
test_timeoutFunction · 0.85
test_error_eofFunction · 0.85
test_dispatchFunction · 0.85
test_ev_clearFunction · 0.85
test_dual_read_writeFunction · 0.85
test_ev_clearFunction · 0.85
test_dispatchFunction · 0.85

Calls 8

hook_onceFunction · 0.85
kqueue_allocFunction · 0.85
socketFunction · 0.70
fiber_io_eventFunction · 0.50
event_handleFunction · 0.50
msg_infoFunction · 0.50
msg_errorFunction · 0.50
last_serrorFunction · 0.50

Tested by 11

test_dual_read_writeFunction · 0.68
test_oneshotFunction · 0.68
test_disable_enableFunction · 0.68
test_deleteFunction · 0.68
test_timeoutFunction · 0.68
test_error_eofFunction · 0.68
test_dispatchFunction · 0.68
test_ev_clearFunction · 0.68
test_dual_read_writeFunction · 0.68
test_ev_clearFunction · 0.68
test_dispatchFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…