summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);