X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-session.c;h=c312b46cbd9adc150dbaf9ea9a9d037959d9c303;hb=96ee1e30743b88780cc9dc975745d8dc03de25ae;hp=c23d414bc14b478509006d4097f4f27e554d2faa;hpb=f6a6c26058c8b6ca7500c84ffe13ca2b2dc8b49e;p=src%2Fapp-framework-binder.git diff --git a/src/afb-session.c b/src/afb-session.c index c23d414b..c312b46c 100644 --- a/src/afb-session.c +++ b/src/afb-session.c @@ -40,7 +40,7 @@ #define _MAXEXP_ ((time_t)(~(time_t)0)) #define _MAXEXP2_ ((time_t)((((unsigned long long)_MAXEXP_) >> 1))) #define MAX_EXPIRATION (_MAXEXP_ >= 0 ? _MAXEXP_ : _MAXEXP2_) -#define NOW (time(NULL)) +#define NOW (time_now()) /* structure for a cookie added to sessions */ struct cookie @@ -86,6 +86,14 @@ static struct { .mutex = PTHREAD_MUTEX_INITIALIZER }; +/* Get the actual raw time */ +static inline time_t time_now() +{ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC_RAW, &ts); + return ts.tv_sec; +} + /* generate a new fresh 'uuid' */ static void new_uuid(char uuid[SIZEUUID]) { @@ -346,6 +354,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 */