# HG changeset patch # User Sebastien Decugis # Date 1273468251 -32400 # Node ID 2d3a799ad29c23570e07804defec564cb2cdd434 # Parent 7842bed901cabcadd7ee26bf45d2ca4305e7cf74 Cache the session pointer in answers when it was present in queries diff -r 7842bed901ca -r 2d3a799ad29c libfreeDiameter/libfD.h --- a/libfreeDiameter/libfD.h Fri May 07 16:33:12 2010 +0900 +++ b/libfreeDiameter/libfD.h Mon May 10 14:10:51 2010 +0900 @@ -61,6 +61,7 @@ /* Messages / sessions API */ int fd_sess_fromsid_msg ( unsigned char * sid, size_t len, struct session ** session, int * new); +int fd_sess_ref_msg ( struct session * session ); int fd_sess_reclaim_msg ( struct session ** session ); #endif /* _LIBFD_H */ diff -r 7842bed901ca -r 2d3a799ad29c libfreeDiameter/messages.c --- a/libfreeDiameter/messages.c Fri May 07 16:33:12 2010 +0900 +++ b/libfreeDiameter/messages.c Mon May 10 14:10:51 2010 +0900 @@ -335,6 +335,8 @@ val.os.len = strlen(sid); CHECK_FCT( fd_msg_avp_setvalue( avp, &val ) ); CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_FIRST_CHILD, avp ) ); + ans->msg_sess = sess; + CHECK_FCT( fd_sess_ref_msg(sess) ); } /* associate with query */ @@ -2207,13 +2209,13 @@ /* So start browsing the message */ CHECK_FCT_DO( ret = fd_msg_browse( *msg, MSG_BRW_FIRST_CHILD, &avp, NULL ), goto error ); while (avp != NULL) { - /* Sanity */ - ASSERT( avp->avp_public.avp_value ); - /* For unknown AVP, we don't have a callback registered, so just skip */ if (avp->avp_model) { struct dict_object * type, * enumval; + /* Sanity */ + ASSERT( avp->avp_public.avp_value ); + /* Get the list of callback for this AVP */ CHECK_FCT_DO( ret = fd_dict_disp_cb(DICT_AVP, avp->avp_model, &cb_list), goto error ); diff -r 7842bed901ca -r 2d3a799ad29c libfreeDiameter/sessions.c --- a/libfreeDiameter/sessions.c Fri May 07 16:33:12 2010 +0900 +++ b/libfreeDiameter/sessions.c Mon May 10 14:10:51 2010 +0900 @@ -711,15 +711,26 @@ /* Get the session object */ CHECK_FCT( fd_sess_fromsid ( (char *) sid, len, session, new) ); - /* Update the msg refcount */ - CHECK_POSIX( pthread_mutex_lock(&(*session)->stlock) ); - (*session)->msg_cnt++; - CHECK_POSIX( pthread_mutex_unlock(&(*session)->stlock) ); + /* Increase count */ + CHECK_FCT( fd_sess_ref_msg ( *session ) ); /* Done */ return 0; } +int fd_sess_ref_msg ( struct session * session ) +{ + TRACE_ENTRY("%p", session); + CHECK_PARAMS( VALIDATE_SI(session) ); + + /* Update the msg refcount */ + CHECK_POSIX( pthread_mutex_lock(&session->stlock) ); + session->msg_cnt++; + CHECK_POSIX( pthread_mutex_unlock(&session->stlock) ); + + return 0; +} + int fd_sess_reclaim_msg ( struct session ** session ) { int reclaim;