diff libfreeDiameter/sessions.c @ 6:b0d377c79d80

Progress on dispatch API spec; added fd_sess_reclaim function and test
author Sebastien Decugis <sdecugis@nict.go.jp>
date Thu, 03 Sep 2009 16:03:25 +0900
parents c2d2729e3603
children e5af94b04946
line wrap: on
line diff
--- a/libfreeDiameter/sessions.c	Thu Sep 03 14:33:45 2009 +0900
+++ b/libfreeDiameter/sessions.c	Thu Sep 03 16:03:25 2009 +0900
@@ -241,7 +241,7 @@
 }
 
 /* Create a new handler */
-int fd_sess_handler_create_int ( struct session_handler ** handler, void (*cleanup)(char * sid, session_state * state) )
+int fd_sess_handler_create_internal ( struct session_handler ** handler, void (*cleanup)(char * sid, session_state * state) )
 {
 	struct session_handler *new;
 	
@@ -564,10 +564,36 @@
 	return 0;
 }
 
+/* Destroy a session if it is not used */
+int fd_sess_reclaim ( struct session ** session )
+{
+	struct session * sess;
+	
+	TRACE_ENTRY("%p", session);
+	CHECK_PARAMS( session && VALIDATE_SI(*session) );
+	
+	sess = *session;
+	*session = NULL;
+	
+	CHECK_FCT( pthread_mutex_lock( H_LOCK(sess->hash) ) );
+	CHECK_FCT( pthread_mutex_lock( &exp_lock ) );
+	if (FD_IS_LIST_EMPTY(&sess->states)) {
+		fd_list_unlink( &sess->chain_h );
+		fd_list_unlink( &sess->expire );
+		sess->eyec = 0xdead;
+		free(sess->sid);
+		free(sess);
+	}
+	CHECK_FCT( pthread_mutex_unlock( &exp_lock ) );
+	CHECK_FCT( pthread_mutex_unlock( H_LOCK(sess->hash) ) );
+	
+	return 0;
+}
+
 
 
 /* Save a state information with a session */
-int fd_sess_state_store_int ( struct session_handler * handler, struct session * session, session_state ** state )
+int fd_sess_state_store_internal ( struct session_handler * handler, struct session * session, session_state ** state )
 {
 	struct state *new;
 	struct fd_list * li;
@@ -616,7 +642,7 @@
 }
 
 /* Get the data back */
-int fd_sess_state_retrieve_int ( struct session_handler * handler, struct session * session, session_state ** state )
+int fd_sess_state_retrieve_internal ( struct session_handler * handler, struct session * session, session_state ** state )
 {
 	struct fd_list * li;
 	struct state * st = NULL;
"Welcome to our mercurial repository"