changeset 291:2d3a799ad29c

Cache the session pointer in answers when it was present in queries
author Sebastien Decugis <sdecugis@nict.go.jp>
date Mon, 10 May 2010 14:10:51 +0900
parents 7842bed901ca
children a77ed0e30ac9
files libfreeDiameter/libfD.h libfreeDiameter/messages.c libfreeDiameter/sessions.c
diffstat 3 files changed, 21 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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 */
--- 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 );
 			
--- 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;
"Welcome to our mercurial repository"