diff options
author | Toni <matzeton@googlemail.com> | 2023-11-06 12:38:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-06 12:38:15 +0100 |
commit | 1b679271693a17ce0b653b9ba45db77b731db42e (patch) | |
tree | 986a2fac5feeaae71e2c2bd4e771e31a7c966de6 /nio.h | |
parent | 17c21e1d27a90b394873a0e80e5d6992f4b985ee (diff) |
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 <matzeton@googlemail.com>
Diffstat (limited to 'nio.h')
-rw-r--r-- | nio.h | 28 |
1 files changed, 23 insertions, 5 deletions
@@ -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); |