From a6a7b67d720ce2a2f1a3e5d5a7eeac3f01cf16d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Fri, 27 Jun 2025 23:29:09 +0200 Subject: [PATCH] build on osx --- src/iomux_epoll.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/iomux_epoll.c b/src/iomux_epoll.c index d18e227..d5ae10f 100644 --- a/src/iomux_epoll.c +++ b/src/iomux_epoll.c @@ -1,12 +1,13 @@ +#ifdef __linux__ #include #include #include -#include #include #include +#include #include "iomux_impl.h" -//epoll (linux specific) IO mux. +//epoll (linux specific) IO mux. //We stuff the struct IOMuxFD pointer in the event.data.ptr slot //for the kernel to keep track of, so we don't have to. ///we do not use edge triggered mode @@ -29,10 +30,10 @@ static inline uint32_t mux_2_epoll_events(unsigned int events) { uint32_t epoll_events = 0; - if (events & MUX_EV_READ) + if (events & MUX_EV_READ) epoll_events |= EPOLLIN; - if (events & MUX_EV_WRITE) + if (events & MUX_EV_WRITE) epoll_events |= EPOLLOUT; return epoll_events; @@ -47,7 +48,7 @@ static inline unsigned int epoll_2_mux_events(uint32_t events) if (events & (EPOLLIN | EPOLLHUP | EPOLLERR)) mux_events |= MUX_EV_READ; - if (events & EPOLLOUT) + if (events & EPOLLOUT) mux_events |= MUX_EV_WRITE; return mux_events; @@ -58,10 +59,10 @@ static int iomux_epoll_update_events(struct IOMux *mux_, struct IOMuxFD *fd) struct IOMuxEpoll *mux = mux_->instance; struct epoll_event e_event = {0, {0}}; int rc; - + e_event.events = mux_2_epoll_events(fd->what); e_event.data.ptr = fd; - + rc = epoll_ctl(mux->epoll_fd, EPOLL_CTL_MOD, fd->fd, &e_event); assert(rc == 0); if (rc != 0) @@ -117,7 +118,7 @@ static int iomux_epoll_unregister_fd(struct IOMux *mux_, struct IOMuxFD *fd) break; } } - + mux->num_descriptors--; return rc; @@ -145,10 +146,10 @@ static int iomux_epoll_run(struct IOMux *mux_, struct timeval *timeout) //epoll takes the timeout in miliseconds if (timeout) timeout_ms = timeval_to_ms(timeout); - else + else timeout_ms = -1; - do { + do { rc = epoll_wait(mux->epoll_fd, mux->pending_events, EPOLL_WAIT_EVENTS, timeout_ms); @@ -173,14 +174,14 @@ static int iomux_epoll_run(struct IOMux *mux_, struct timeval *timeout) //we want to deliver only one event at a time to simplify //application programming. - if (events & MUX_EV_READ && fd != NULL) { + if (events & MUX_EV_READ && fd != NULL) { assert(fd->callback != NULL); fd->callback(mux_, fd, MUX_EV_READ); } //now re-check, in case the IOMuxFD was removed fd = mux->pending_events[i].data.ptr; - if (events & MUX_EV_WRITE && fd != NULL) { + if (events & MUX_EV_WRITE && fd != NULL) { assert(fd->callback != NULL); fd->callback(mux_, fd, MUX_EV_WRITE); } @@ -211,7 +212,7 @@ static const struct IOMuxOps epoll_ops = { .unregister_fd_impl = iomux_epoll_unregister_fd, .update_events_impl = iomux_epoll_update_events, }; - + int iomux_epoll_init(struct IOMux *mux) { struct IOMuxEpoll *mux_epoll = calloc(1, sizeof *mux_epoll); @@ -230,3 +231,12 @@ int iomux_epoll_init(struct IOMux *mux) return 0; } +#else +#include +#include "iomux_impl.h" + +int iomux_epoll_init(struct IOMux *mux) +{ + return ENOSYS; +} +#endif