From 1b679271693a17ce0b653b9ba45db77b731db42e Mon Sep 17 00:00:00 2001 From: Toni Date: Mon, 6 Nov 2023 12:38:15 +0100 Subject: Event I/O abstraction layer. (#28) * Finalize Event I/O abstraction layer. * Fix possible fd leakage, Gitlab-CI build and error logging. * Fixed possible uninitialized signalfd variable. * Fixed possible memory leak. * Fixed some SonarCloud complaints. * Fixed nDPId-test nDPIsrvd-arpa-mockup stuck indefinitely. * Add nDPId / nDPIsrvd command line option to use poll() on Linux instead of the default epoll(). Signed-off-by: Toni Uhlig --- nio.h | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'nio.h') diff --git a/nio.h b/nio.h index d1f5add72..a0ac0b6b0 100644 --- a/nio.h +++ b/nio.h @@ -5,7 +5,7 @@ enum { - NIO_ERROR_SUCCESS = 0, + NIO_SUCCESS = 0, NIO_ERROR_INTERNAL = 1, NIO_ERROR_SYSTEM = -1 }; @@ -23,9 +23,9 @@ struct nio int nready; nfds_t poll_max_fds; - nfds_t poll_cur_fds; struct pollfd * poll_fds; void ** poll_ptrs; + nfds_t * poll_fds_set; int epoll_fd; int max_events; @@ -46,15 +46,33 @@ int nio_del_fd(struct nio * io, int fd); int nio_run(struct nio * io, int timeout); +static inline int nio_get_nready(struct nio const * const io) +{ + return io->nready; +} + int nio_check(struct nio * io, int index, int events); int nio_is_valid(struct nio * io, int index); -int nio_has_input(struct nio * io, int index); +int nio_get_fd(struct nio * io, int index); -int nio_can_output(struct nio * io, int index); +void * nio_get_ptr(struct nio * io, int index); + +static inline int nio_has_input(struct nio * io, int index) +{ + return nio_check(io, index, NIO_EVENT_INPUT); +} -int nio_has_error(struct nio * io, int index); +static inline int nio_can_output(struct nio * io, int index) +{ + return nio_check(io, index, NIO_EVENT_OUTPUT); +} + +static inline int nio_has_error(struct nio * io, int index) +{ + return nio_check(io, index, NIO_EVENT_ERROR); +} void nio_free(struct nio * io); -- cgit v1.2.3