From 7356408ca1554468c9d7b9840aaaee28b4341c8d Mon Sep 17 00:00:00 2001 From: Jordan Augé Date: Wed, 9 Sep 2020 11:59:36 +0200 Subject: [HICN-563] listener and connection tables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I88b85a61908d97bda1afb08d31c3bf10b4d9c5c5 Signed-off-by: Jordan Augé --- hicn-light/src/hicn/core/connection_table.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'hicn-light/src/hicn/core/connection_table.c') diff --git a/hicn-light/src/hicn/core/connection_table.c b/hicn-light/src/hicn/core/connection_table.c index fd8013b73..0b7df0384 100644 --- a/hicn-light/src/hicn/core/connection_table.c +++ b/hicn-light/src/hicn/core/connection_table.c @@ -18,22 +18,35 @@ * \brief Implementation of hICN connection table */ -#include -#include +#include -/* This is only used for first allocation, as the table is resizeable */ +#include "connection.h" +#include "connection_table.h" + +/* This is only used as a hint for first allocation, as the table is resizeable */ #define DEFAULT_CONNECTION_TABLE_SIZE 64 connection_table_t * -connection_table_create(size_t elt_size, size_t max_elts) +_connection_table_create(size_t init_size, size_t max_size) { + if (init_size == 0) + init_size = DEFAULT_CONNECTION_TABLE_SIZE; + connection_table_t * table = malloc(sizeof(connection_table_t)); if (!table) return NULL; + table->max_size = max_size; + + /* Initialize indices */ table->id_by_pair = kh_init_ct_pair(); table->id_by_name = kh_init_ct_name(); - pool_init(table->connections, DEFAULT_CONNECTION_TABLE_SIZE); + + /* + * We start by allocating a reasonably-sized pool, as this will eventually + * be resized if needed. + */ + pool_init(table->connections, init_size); return table; } @@ -57,7 +70,7 @@ connection_table_get_by_pair(const connection_table_t * table, return table->connections + kh_val(table->id_by_pair, k); } -unsigned +off_t connection_table_get_id_by_name(const connection_table_t * table, const char * name) { -- cgit 1.2.3-korg