implementation session manager

This commit is contained in:
luwenpeng
2023-12-19 10:47:26 +08:00
parent 2e56bd810c
commit 2c26879182
15 changed files with 2269 additions and 193 deletions

View File

@@ -12,8 +12,8 @@ struct session_table
void *arg;
uint64_t count;
struct session *oldest_ptr;
struct session *newest_ptr;
struct session *least_recently_unused;
struct session *least_recently_used;
};
/******************************************************************************
@@ -52,19 +52,19 @@ static void session_table_add_session_to_linklist(struct session_table *table, s
return;
}
if (table->newest_ptr == NULL)
if (table->least_recently_used == NULL)
{
table->oldest_ptr = sess;
table->newest_ptr = sess;
table->least_recently_unused = sess;
table->least_recently_used = sess;
sess->prev_ptr = NULL;
sess->next_ptr = NULL;
}
else
{
sess->next_ptr = table->newest_ptr;
table->newest_ptr->prev_ptr = sess;
sess->next_ptr = table->least_recently_used;
table->least_recently_used->prev_ptr = sess;
sess->prev_ptr = NULL;
table->newest_ptr = sess;
table->least_recently_used = sess;
}
}
@@ -77,17 +77,17 @@ static void session_table_del_session_from_linklist(struct session_table *table,
if (sess->prev_ptr == NULL && sess->next_ptr == NULL)
{
table->oldest_ptr = NULL;
table->newest_ptr = NULL;
table->least_recently_unused = NULL;
table->least_recently_used = NULL;
}
else if (sess->prev_ptr == NULL && sess->next_ptr != NULL)
{
table->newest_ptr = sess->next_ptr;
table->least_recently_used = sess->next_ptr;
sess->next_ptr->prev_ptr = NULL;
}
else if (sess->prev_ptr != NULL && sess->next_ptr == NULL)
{
table->oldest_ptr = sess->prev_ptr;
table->least_recently_unused = sess->prev_ptr;
sess->prev_ptr->next_ptr = NULL;
}
else
@@ -107,8 +107,8 @@ struct session_table *session_table_create()
{
struct session_table *table = (struct session_table *)calloc(1, sizeof(struct session_table));
table->count = 0;
table->oldest_ptr = NULL;
table->newest_ptr = NULL;
table->least_recently_unused = NULL;
table->least_recently_used = NULL;
return table;
}
@@ -204,25 +204,31 @@ struct session *session_table_find_session(struct session_table *table, const st
struct session *sess = NULL;
HASH_FIND(hh, table->root, tuple, sizeof(struct tuple6), sess);
if (sess)
{
session_table_del_session_from_linklist(table, sess);
session_table_add_session_to_linklist(table, sess);
}
return sess;
}
struct session *session_table_find_oldest_session(struct session_table *table)
struct session *session_table_find_least_recently_unused_session(struct session_table *table)
{
if (table == NULL)
{
return NULL;
}
return table->oldest_ptr;
return table->least_recently_unused;
}
struct session *session_table_find_newest_session(struct session_table *table)
struct session *session_table_find_least_recently_used_session(struct session_table *table)
{
if (table == NULL)
{
return NULL;
}
return table->newest_ptr;
return table->least_recently_used;
}