[icinga-checkins] icinga.org: icinga-core/mfriedrich/workers: libicinga: add iobroker_is_registered(fd), make iobroker_poll return number of triggered fd's #2953
git at icinga.org
git at icinga.org
Sun Aug 5 23:32:12 CEST 2012
Module: icinga-core
Branch: mfriedrich/workers
Commit: 88963381b0564e83b6fb5a182b260989f2756ba7
URL: https://git.icinga.org/?p=icinga-core.git;a=commit;h=88963381b0564e83b6fb5a182b260989f2756ba7
Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date: Sun Aug 5 14:05:41 2012 +0200
libicinga: add iobroker_is_registered(fd), make iobroker_poll return number of triggered fd's #2953
iobroker_is_registered(fd) is more like a debugging function, as callers
should know which fds they have registered, but it might be helpful as
sanity check either way for user's applications using libicinga.
iobroker_poll() now returns the number of triggered filedescriptors, in
order to tell if we actually got some input from our fds registered to
the broker.
refs #2953
---
lib/iobroker.c | 14 ++++++++++++--
lib/iobroker.h | 8 ++++++++
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/lib/iobroker.c b/lib/iobroker.c
index e69f106..6324a24 100644
--- a/lib/iobroker.c
+++ b/lib/iobroker.c
@@ -243,6 +243,13 @@ int iobroker_register(iobroker_set *iobs, int fd, void *arg, int (*handler)(int,
return 0;
}
+int iobroker_is_registered(iobroker_set *iobs, int fd) {
+
+ if (!iobs || fd < 0 || fd > iobs->max_fds || !iobs->iobroker_fds[fd])
+ return 0;
+
+ return iobs->iobroker_fds[fd]->fd == fd;
+}
int iobroker_unregister(iobroker_set *iobs, int fd) {
if (!iobs)
@@ -322,7 +329,7 @@ void iobroker_destroy(iobroker_set *iobs, int flags) {
int iobroker_poll(iobroker_set *iobs, int timeout) {
- int i, nfds;
+ int i, nfds, ret = 0;
if (!iobs)
return IOBROKER_ENOSET;
@@ -348,6 +355,7 @@ int iobroker_poll(iobroker_set *iobs, int timeout) {
if (s) {
s->handler(fd, iobs->ep_events[i].events, s->arg);
+ ret++;
}
}
#elif defined(IOBROKER_USES_SELECT)
@@ -392,6 +400,7 @@ int iobroker_poll(iobroker_set *iobs, int timeout) {
continue;
}
s->handler(s->fd, POLLIN, s->arg);
+ ret++;
}
}
}
@@ -426,9 +435,10 @@ int iobroker_poll(iobroker_set *iobs, int timeout) {
continue;
}
s->handler(s->fd, (int)iobs->pfd[i].revents, s->arg);
+ ret++;
}
}
#endif
- return 0;
+ return ret;
}
diff --git a/lib/iobroker.h b/lib/iobroker.h
index 98c3664..914a98e 100644
--- a/lib/iobroker.h
+++ b/lib/iobroker.h
@@ -106,6 +106,13 @@ extern int iobroker_max_usable_fds(void);
*/
extern int iobroker_register(iobroker_set *iobs, int sd, void *arg, int (*handler)(int, int, void *));
+/**
+ * Check if a particular filedescriptor is registered with the iobroker set
+ * @param[in] The iobroker set the filedescriptor should be member of
+ * @param[in] The filedescritpro to check for
+ * @return 1 if the filedescriptor is registered and 0 otherwise
+ */
+extern int iobroker_is_registered(iobroker_set *iobs, int fd);
/**
* Getter function for number of file descriptors registered in
@@ -165,6 +172,7 @@ extern void iobroker_destroy(iobroker_set *iobs, int flags);
* Wait for input on any of the registered sockets.
* @param iobs The socket set to wait for.
* @param timeout Timeout in milliseconds. -1 is "wait indefinitely"
+ * @return -1 on errors, or number of filedescriptors with input
*/
extern int iobroker_poll(iobroker_set *iobs, int timeout);
#endif /* INCLUDE_iobroker_h__ */
More information about the icinga-checkins
mailing list