aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/core/connection_table.c
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge+fdio@cisco.com>2020-09-09 11:59:36 +0200
committerJordan Augé <jordan.auge+fdio@cisco.com>2020-09-21 14:49:29 +0200
commit7356408ca1554468c9d7b9840aaaee28b4341c8d (patch)
treef57bfcc87be4cf5b51b86e5c847b4cde24c0d5e0 /hicn-light/src/hicn/core/connection_table.c
parentfe310f8b7a54f31b7270107b57b5ffcc00966f45 (diff)
[HICN-563] listener and connection tables
Change-Id: I88b85a61908d97bda1afb08d31c3bf10b4d9c5c5 Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com>
Diffstat (limited to 'hicn-light/src/hicn/core/connection_table.c')
-rw-r--r--hicn-light/src/hicn/core/connection_table.c25
1 files changed, 19 insertions, 6 deletions
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 <hicn/core/connection.h>
-#include <hicn/core/connection_table.h>
+#include <hicn/util/log.h>
-/* 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)
{