Navigation


Changeset 85:e5fcd672caff in freeDiameter for libfreeDiameter/sessions.c


Ignore:
Timestamp:
Dec 3, 2009, 2:59:23 PM (14 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Added new function to retrieve messages sessions easily

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfreeDiameter/sessions.c

    r14 r85  
    100100        pthread_mutex_t stlock; /* A lock to protect the list of states associated with this session */
    101101        struct fd_list  states; /* Sentinel for the list of states of this session. */
     102        int             msg_cnt;/* Reference counter for the messages pointing to this session */
    102103};
    103104
     
    675676}
    676677
     678/* For the messages module */
     679int fd_sess_fromsid_msg ( unsigned char * sid, size_t len, struct session ** session, int * new)
     680{
     681        TRACE_ENTRY("%p %zd %p %p", sid, len, session, new);
     682        CHECK_PARAMS( sid && len && session && VALIDATE_SI(*session) );
     683       
     684        /* Get the session object */
     685        CHECK_FCT( fd_sess_fromsid ( (char *) sid, len, session, new) );
     686       
     687        /* Update the msg refcount */
     688        CHECK_POSIX( pthread_mutex_lock(&(*session)->stlock) );
     689        (*session)->msg_cnt++;
     690        CHECK_POSIX( pthread_mutex_unlock(&(*session)->stlock) );
     691       
     692        /* Done */
     693        return 0;
     694}
     695
     696int fd_sess_reclaim_msg ( struct session ** session )
     697{
     698        int reclaim;
     699       
     700        TRACE_ENTRY("%p", session);
     701        CHECK_PARAMS( session && VALIDATE_SI(*session) );
     702       
     703        /* Update the msg refcount */
     704        CHECK_POSIX( pthread_mutex_lock(&(*session)->stlock) );
     705        reclaim = (*session)->msg_cnt;
     706        (*session)->msg_cnt = reclaim - 1;
     707        CHECK_POSIX( pthread_mutex_unlock(&(*session)->stlock) );
     708       
     709        if (reclaim == 1) {
     710                CHECK_FCT(fd_sess_reclaim ( session ));
     711        } else {
     712                *session = NULL;
     713        }
     714        return 0;
     715}
     716
     717
    677718
    678719/* Dump functions */
Note: See TracChangeset for help on using the changeset viewer.