From 5fccb2dcb97fac7fbc16d66e947477e41d30a2b4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Mon, 12 Feb 2018 14:27:46 +0100 Subject: [PATCH] afb-session: Add function to enumerate sessions MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: Ifaa1aa02d0562c40763ac03b7c05df7f9f9c8127 Signed-off-by: José Bollo --- src/afb-session.c | 22 ++++++++++++++++++++++ src/afb-session.h | 1 + 2 files changed, 23 insertions(+) diff --git a/src/afb-session.c b/src/afb-session.c index c23d414b..17ca7af8 100644 --- a/src/afb-session.c +++ b/src/afb-session.c @@ -346,6 +346,28 @@ int afb_session_init (int max_session_count, int timeout, const char *initok) return 0; } +/** + * Iterate the sessions and call 'callback' with + * the 'closure' for each session. + */ +void afb_session_foreach(void (*callback)(void *closure, struct afb_session *session), void *closure) +{ + struct afb_session *session; + int idx; + + /* Loop on Sessions Table and remove anything that is older than timeout */ + sessionset_lock(); + for (idx = 0 ; idx < HEADCOUNT; idx++) { + session = sessions.heads[idx]; + while (session) { + if (!session->closed) + callback(closure, session); + session = session->next; + } + } + sessionset_unlock(); +} + /** * Cleanup the sessionset of its closed or expired sessions */ diff --git a/src/afb-session.h b/src/afb-session.h index 2fdd1a64..c93db5c4 100644 --- a/src/afb-session.h +++ b/src/afb-session.h @@ -26,6 +26,7 @@ struct afb_session; extern int afb_session_init(int max_session_count, int timeout, const char *initok); extern void afb_session_purge(); extern const char *afb_session_initial_token(); +extern void afb_session_foreach(void (*callback)(void *closure, struct afb_session *session), void *closure); extern struct afb_session *afb_session_create (int timeout); extern struct afb_session *afb_session_search (const char *uuid); -- 2.16.6