|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2021 nono project
4: // Licensed under nono-license.txt
5: //
6:
1.1.1.2 ! root 7: //
! 8: // kqueue/kevent をいろいろ便利にする
! 9: //
! 10:
1.1 root 11: #pragma once
12:
1.1.1.2 ! root 13: #include "header.h"
! 14:
1.1 root 15: #include <sys/types.h>
16: #if defined(HAVE_SYS_EVENT_H)
17: #include <sys/event.h>
18: #endif
19: #if defined(HAVE_KQUEUE_SYS_EVENT_H)
20: #include <kqueue/sys/event.h>
21: #endif
22: #include <sys/time.h>
23:
24: // udata の型は環境によって異なる
25: using kevent_udata_t = decltype(kevent::udata);
26:
1.1.1.2 ! root 27: // udata と int の相互変換
! 28: static inline kevent_udata_t
! 29: EV_INT2UDATA(int x)
! 30: {
! 31: return (kevent_udata_t)(intptr_t)x;
! 32: }
! 33: static inline int
! 34: EV_UDATA2INT(kevent_udata_t x)
! 35: {
! 36: return (int)(intptr_t)x;
! 37: }
! 38:
1.1 root 39: #define kevent_set(k, e, n) kevent((k), (e), (n), NULL, 0, NULL)
40: #define kevent_poll(k, e, n, t) kevent((k), NULL, 0, (e), (n), (t))
1.1.1.2 ! root 41:
! 42: static inline int
! 43: kevent_add(int kq, int fd, int filter, int action, int udata)
! 44: {
! 45: struct kevent kev;
! 46:
! 47: EV_SET(&kev, fd, filter, action, 0, 0, EV_INT2UDATA(udata));
! 48: return kevent_set(kq, &kev, 1);
! 49: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.