From 2a6bbac712248a3d1ab4c24ece7e4ff7aac32f67 Mon Sep 17 00:00:00 2001 From: Roman Khromenok <121662006+khromenokroman@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:30:40 +0200 Subject: [PATCH] replace select to poll (#584) * replace select * Added poll/select selection during compilation --------- Co-authored-by: Olof Hagsand --- configure.ac | 7 +++++++ include/clixon_custom.h | 3 ++- lib/src/clixon_event.c | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index c4306515..6202520d 100644 --- a/configure.ac +++ b/configure.ac @@ -465,6 +465,13 @@ AH_BOTTOM([#include ]) test "x$prefix" = xNONE && prefix=$ac_default_prefix +AC_ARG_ENABLE([event-poll], + AS_HELP_STRING([--enable-event-poll], [Enable event polling feature]), + [if test "$enable_event_poll" = "yes"; then + AC_DEFINE([CLIXON_EVENT_POLL], 1, [Enable event polling feature]) + fi] +) + AC_CONFIG_FILES([Makefile lib/Makefile lib/src/Makefile diff --git a/include/clixon_custom.h b/include/clixon_custom.h index 97248fda..964567f5 100644 --- a/include/clixon_custom.h +++ b/include/clixon_custom.h @@ -213,8 +213,8 @@ * This causes xml_cmp to show that the datastores are unequal and may cause a wrong diff, or * worse case an overwrite. */ -#undef SYSTEM_ONLY_CONFIG_CANDIDATE_CLEAR +#undef SYSTEM_ONLY_CONFIG_CANDIDATE_CLEAR /*! In full XPath namespace resolve, match even if namespace not resolved * * In the case of xpath lookup functions (eg xpath_vec_ctx) where nsc is defined, then @@ -224,3 +224,4 @@ * This seems wrong and should be changed, but need further investigation */ #define XPATH_NS_ACCEPT_UNRESOLVED + diff --git a/lib/src/clixon_event.c b/lib/src/clixon_event.c index 2e6b4f96..691954a0 100644 --- a/lib/src/clixon_event.c +++ b/lib/src/clixon_event.c @@ -69,6 +69,10 @@ #include "clixon_options.h" #include "clixon_event.h" +#ifdef CLIXON_EVENT_POLL +#include +#endif + /* * Constants */ @@ -353,6 +357,24 @@ clixon_event_unreg_timeout(int (*fn)(int, void*), * @retval 0 Nothing to read/empty fd * @retval -1 Error */ +#ifdef CLIXON_EVENT_POLL +int +clixon_event_poll(int fd) { + struct pollfd pfd; + int retval; + + pfd.fd = fd; + pfd.events = POLLIN; + + retval = poll(&pfd, 1, 0); + + if (retval < 0) { + clixon_err(OE_EVENTS, errno, "poll"); + } + + return retval; +} +#else int clixon_event_poll(int fd) { @@ -366,6 +388,7 @@ clixon_event_poll(int fd) clixon_err(OE_EVENTS, errno, "select"); return retval; } +#endif /*! Dispatch file descriptor events (and timeouts) by invoking callbacks. *