From e643adbd427252b132d0d1fa5e7c11e3be3e6a6e Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 24 Jul 2021 15:23:55 +0000 Subject: [PATCH] adding some code to use kqueue() --- hio/lib/sys-mux.c | 33 +++++++++++++++++++++++++++++++++ hio/lib/sys-prv.h | 13 +++++++++++++ 2 files changed, 46 insertions(+) diff --git a/hio/lib/sys-mux.c b/hio/lib/sys-mux.c index f69fcc7..1544345 100644 --- a/hio/lib/sys-mux.c +++ b/hio/lib/sys-mux.c @@ -87,6 +87,29 @@ int hio_sys_initmux (hio_t* hio) mux->map.ptr[mux->ctrlp[0]] = idx; } +#elif defined(USE_KQUEUE) + #if defined(HAVE_KQUEUE1) && defined(O_CLOEXEC) + mux->kq = kqueue1(O_CLOEXEC); + if (mux->kq <= -1) + { + hio_seterrwithsyserr (hio, 0, errno); + return -1; + } + #else + mux->kq = kqueue(); + if (mux->kq <= -1) + { + hio_seterrwithsyserr (hio, 0, errno); + return -1; + } + else + { + #if defined(FD_CLOEXEC) + int flags = fcntl(mux->kq, F_GETFD); + if (flags >= 0) fcntl (mux->kq, F_SETFD, flag | FD_CLOEXEC); + #endif + } + #endif #elif defined(USE_EPOLL) @@ -160,6 +183,16 @@ void hio_sys_finimux (hio_t* hio) } mux->pd.capa = 0; +#elif defined(USE_KQUEUE) + if (mux->ctrlp[0] != HIO_SYSHND_INVALID) + { + /* TODO: */ + } + + close (mux->kq); + mux->kq = HIO_SYSHND_INVALID; + + #elif defined(USE_EPOLL) if (mux->ctrlp[0] != HIO_SYSHND_INVALID) { diff --git a/hio/lib/sys-prv.h b/hio/lib/sys-prv.h index 32cab32..9b0e174 100644 --- a/hio/lib/sys-prv.h +++ b/hio/lib/sys-prv.h @@ -31,6 +31,9 @@ #include "hio-prv.h" +#if defined(HAVE_SYS_EVENT_H) && defined(HAVE_KQUEUE) && defined(HAVE_KEVENT) +# include +# define USE_KQUEUE #if defined(HAVE_SYS_EPOLL_H) # include # define USE_EPOLL @@ -67,6 +70,16 @@ struct hio_sys_mux_t int ctrlp[2]; }; +#elif defined(USE_KQUEUE) + +struct hio_sys_mutx_t +{ + int kq; + + struct kevent revs[1024]; /* TODO: is it a good size? */ + + int ctrlp[2]; +}; #elif defined(USE_EPOLL) struct hio_sys_mux_t