+ prv = &sessions.first;
+ while ((session = *prv)) {
+ session_lock(session);
+ if (force || session->expiration < now)
+ session_close(session);
+ if (!session->closed) {
+ prv = &session->next;
+ session_unlock(session);
+ } else {
+ *prv = session->next;
+ sessions.count--;
+ session->notinset = 1;
+ if (session->refcount)
+ session_unlock(session);
+ else
+ session_destroy(session);
+ }
+ }
+ return now;
+}
+
+/**
+ * Initialize the session manager with a 'max_session_count',
+ * an initial common 'timeout'
+ *
+ * @param max_session_count maximum allowed session count in the same time
+ * @param timeout the initial default timeout of sessions
+ */
+int afb_session_init (int max_session_count, int timeout)
+{
+ /* init the sessionset (after cleanup) */
+ sessionset_lock();
+ sessionset_cleanup(1);
+ if (max_session_count > SESSION_COUNT_MAX)
+ sessions.max = SESSION_COUNT_MAX;
+ else if (max_session_count < SESSION_COUNT_MIN)
+ sessions.max = SESSION_COUNT_MIN;
+ else
+ sessions.max = (uint16_t)max_session_count;
+ sessions.timeout = timeout;
+ sessionset_unlock();
+ 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;