feature: packet IO support IP reassembly

This commit is contained in:
luwenpeng
2024-10-23 10:01:20 +08:00
parent a7b79a0e22
commit fd3cc20554
54 changed files with 3474 additions and 4271 deletions

View File

@@ -1,3 +1,4 @@
#include <assert.h>
#include <stdlib.h>
#include "session_internal.h"
@@ -6,8 +7,9 @@
struct session_pool
{
uint64_t capacity;
uint64_t available;
struct session_list free_list;
uint64_t used;
uint64_t free;
struct session_queue free_list;
};
struct session_pool *session_pool_new(uint64_t capacity)
@@ -17,7 +19,8 @@ struct session_pool *session_pool_new(uint64_t capacity)
{
return NULL;
}
pool->available = 0;
pool->used = 0;
pool->free = 0;
pool->capacity = capacity;
TAILQ_INIT(&pool->free_list);
@@ -26,7 +29,7 @@ struct session_pool *session_pool_new(uint64_t capacity)
{
struct session *sess = &array[i];
TAILQ_INSERT_TAIL(&pool->free_list, sess, free_tqe);
pool->available++;
pool->free++;
}
return pool;
@@ -40,8 +43,10 @@ void session_pool_free(struct session_pool *pool)
while ((sess = TAILQ_FIRST(&pool->free_list)))
{
TAILQ_REMOVE(&pool->free_list, sess, free_tqe);
pool->available--;
pool->free--;
}
assert(pool->free == 0);
assert(pool->used == 0);
free(pool);
pool = NULL;
@@ -59,7 +64,8 @@ struct session *session_pool_pop(struct session_pool *pool)
if (sess)
{
TAILQ_REMOVE(&pool->free_list, sess, free_tqe);
pool->available--;
pool->free--;
pool->used++;
}
return sess;
@@ -73,7 +79,8 @@ void session_pool_push(struct session_pool *pool, struct session *sess)
}
TAILQ_INSERT_TAIL(&pool->free_list, sess, free_tqe);
pool->available++;
pool->free++;
pool->used--;
}
const struct session *session_pool_get0(const struct session_pool *pool, uint64_t idx)
@@ -87,22 +94,12 @@ const struct session *session_pool_get0(const struct session_pool *pool, uint64_
return &array[idx];
}
uint64_t session_pool_available_num(const struct session_pool *pool)
uint64_t session_pool_get_free_num(const struct session_pool *pool)
{
if (pool == NULL)
{
return 0;
}
return pool->available;
return pool->free;
}
uint64_t session_pool_capacity_size(const struct session_pool *pool)
uint64_t session_pool_get_used_num(const struct session_pool *pool)
{
if (pool == NULL)
{
return 0;
}
return pool->capacity;
return pool->used;
}