Mercurial > hg > freeDiameter
diff libfreeDiameter/sessions.c @ 5:c2d2729e3603
Completed new session module tests; some bugs fixed
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Thu, 03 Sep 2009 14:33:45 +0900 |
parents | 883311bf7df3 |
children | b0d377c79d80 |
line wrap: on
line diff
--- a/libfreeDiameter/sessions.c Wed Sep 02 18:28:27 2009 +0900 +++ b/libfreeDiameter/sessions.c Thu Sep 03 14:33:45 2009 +0900 @@ -295,12 +295,13 @@ /* The list is ordered */ if (st->hdl->id < del->id) continue; - if (st->hdl->id > del->id) - break; - /* This state belongs to the handler we are deleting, move the item to the deleted_states list */ - fd_list_unlink(&st->chain); - CHECK_MALLOC( st->sid = strdup(sess->sid) ); - fd_list_insert_before(&deleted_states, &st->chain); + if (st->hdl->id == del->id) { + /* This state belongs to the handler we are deleting, move the item to the deleted_states list */ + fd_list_unlink(&st->chain); + CHECK_MALLOC( st->sid = strdup(sess->sid) ); + fd_list_insert_before(&deleted_states, &st->chain); + } + break; } CHECK_POSIX( pthread_mutex_unlock(&sess->stlock) ); } @@ -399,9 +400,9 @@ break; } - /* If the session did not exist, we can add it into the hash table */ + /* If the session did not exist, we can link it in global tables */ if (!found) { - fd_list_insert_before(li, &sess->chain_h); + fd_list_insert_before(li, &sess->chain_h); /* hash table */ /* We must also insert in the expiry list */ CHECK_POSIX( pthread_mutex_lock( &exp_lock ) ); @@ -409,13 +410,21 @@ /* Find the position in that list. We take it in reverse order */ for (li = exp_sentinel.prev; li != &exp_sentinel; li = li->prev) { struct session * s = (struct session *)(li->o); - if (TS_IS_INFERIOR( &s->timeout, &sess->timeout ) ) break; - - continue; } fd_list_insert_after( li, &sess->expire ); + + #if 0 + if (TRACE_BOOL(ANNOYING)) { + TRACE_DEBUG(FULL, "-- Updated session expiry list --"); + for (li = exp_sentinel.next; li != &exp_sentinel; li = li->next) { + struct session * s = (struct session *)(li->o); + fd_sess_dump(FULL, s); + } + TRACE_DEBUG(FULL, "-- end of expiry list --"); + } + #endif /* We added a new expiring element, we must signal */ CHECK_POSIX( pthread_cond_signal(&exp_cond) ); @@ -502,6 +511,17 @@ /* We added a new expiring element, we must signal */ CHECK_POSIX( pthread_cond_signal(&exp_cond) ); + #if 0 + if (TRACE_BOOL(ANNOYING)) { + TRACE_DEBUG(FULL, "-- Updated session expiry list --"); + for (li = exp_sentinel.next; li != &exp_sentinel; li = li->next) { + struct session * s = (struct session *)(li->o); + fd_sess_dump(FULL, s); + } + TRACE_DEBUG(FULL, "-- end of expiry list --"); + } + #endif + /* We're done */ CHECK_POSIX( pthread_mutex_unlock( &exp_lock ) ); @@ -547,7 +567,7 @@ /* Save a state information with a session */ -int fd_sess_state_store ( struct session_handler * handler, struct session * session, session_state ** state ) +int fd_sess_state_store_int ( struct session_handler * handler, struct session * session, session_state ** state ) { struct state *new; struct fd_list * li; @@ -596,7 +616,7 @@ } /* Get the data back */ -int fd_sess_state_retrieve ( struct session_handler * handler, struct session * session, session_state ** state ) +int fd_sess_state_retrieve_int ( struct session_handler * handler, struct session * session, session_state ** state ) { struct fd_list * li; struct state * st = NULL; @@ -631,29 +651,34 @@ } - /* Dump functions */ void fd_sess_dump(int level, struct session * session) { struct fd_list * li; + char buf[30]; + struct tm tm; + if (!TRACE_BOOL(level)) return; - fd_log_debug("Session @%p:\n", session); + fd_log_debug("\t %*s -- Session @%p --\n", level, "", session); if (!VALIDATE_SI(session)) { - fd_log_debug(" Invalid session object\n"); - return; - } + fd_log_debug("\t %*s Invalid session object\n", level, ""); + } else { - fd_log_debug(" sid '%s', hash %x\n", session->sid, session->hash); - fd_log_debug(" timeout %d.%09d\n", session->timeout.tv_sec, session->timeout.tv_nsec); - - CHECK_POSIX_DO( pthread_mutex_lock(&session->stlock), /* ignore */ ); - for (li = session->states.next; li != &session->states; li = li->next) { - struct state * st = (struct state *)(li->o); - fd_log_debug(" handler %d registered data %p\n", st->hdl->id, st->state); + fd_log_debug("\t %*s sid '%s', hash %x\n", level, "", session->sid, session->hash); + + strftime(buf, sizeof(buf), "%D,%T", localtime_r( &session->timeout.tv_sec , &tm )); + fd_log_debug("\t %*s timeout %s.%09ld\n", level, "", buf, session->timeout.tv_nsec); + + CHECK_POSIX_DO( pthread_mutex_lock(&session->stlock), /* ignore */ ); + for (li = session->states.next; li != &session->states; li = li->next) { + struct state * st = (struct state *)(li->o); + fd_log_debug("\t %*s handler %d registered data %p\n", level, "", st->hdl->id, st->state); + } + CHECK_POSIX_DO( pthread_mutex_unlock(&session->stlock), /* ignore */ ); } - CHECK_POSIX_DO( pthread_mutex_unlock(&session->stlock), /* ignore */ ); + fd_log_debug("\t %*s -- end of session @%p --\n", level, "", session); } void fd_sess_dump_hdl(int level, struct session_handler * handler) @@ -661,11 +686,11 @@ if (!TRACE_BOOL(level)) return; - fd_log_debug("Handler @%p:\n", handler); + fd_log_debug("\t %*s -- Handler @%p --\n", level, "", handler); if (!VALIDATE_SH(handler)) { - fd_log_debug(" Invalid session handler object\n"); - return; + fd_log_debug("\t %*s Invalid session handler object\n", level, ""); + } else { + fd_log_debug("\t %*s id %d, cleanup %p\n", level, "", handler->id, handler->cleanup); } - - fd_log_debug(" id %d, cleanup %p\n", handler->id, handler->cleanup); + fd_log_debug("\t %*s -- end of handler @%p --\n", level, "", handler); }