summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2018-02-12 14:27:46 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2018-02-13 09:20:24 +0100
commit5fccb2dcb97fac7fbc16d66e947477e41d30a2b4 (patch)
tree5f6f6472e3e639922f55f602e1cb4a91e0d53a23
parentf6a6c26058c8b6ca7500c84ffe13ca2b2dc8b49e (diff)
afb-session: Add function to enumerate sessions
Change-Id: Ifaa1aa02d0562c40763ac03b7c05df7f9f9c8127 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-session.c22
-rw-r--r--src/afb-session.h1
2 files changed, 23 insertions, 0 deletions
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
@@ -347,6 +347,28 @@ int afb_session_init (int max_session_count, int timeout, const char *initok)
}
/**
+ * 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
*/
void afb_session_purge()
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);