adding some code to use kqueue()

This commit is contained in:
hyung-hwan 2021-07-24 15:23:55 +00:00
parent a45a99ad78
commit e643adbd42
2 changed files with 46 additions and 0 deletions

View File

@ -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)
{

View File

@ -31,6 +31,9 @@
#include "hio-prv.h"
#if defined(HAVE_SYS_EVENT_H) && defined(HAVE_KQUEUE) && defined(HAVE_KEVENT)
# include <sys/event.h>
# define USE_KQUEUE
#if defined(HAVE_SYS_EPOLL_H)
# include <sys/epoll.h>
# 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