aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light
diff options
context:
space:
mode:
authorEnrico Loparco (eloparco) <eloparco@cisco.com>2021-03-30 17:44:30 +0200
committerEnrico Loparco (eloparco) <eloparco@cisco.com>2021-03-30 17:44:30 +0200
commitf309c4aab4475f5511d00bc236e1f78a457693ed (patch)
tree9c37b91483c3412801cd632f8edcd22fe2cfeebf /hicn-light
parenta5a6ffb506aa3c2a0c7fe8fd09abf3f737984aa5 (diff)
[HICN-555] Fix loop data structure and khash initializations
Signed-off-by: Enrico Loparco (eloparco) <eloparco@cisco.com> Change-Id: I496315ede9b9e9ee2aed79a697e217b8c8b1c211
Diffstat (limited to 'hicn-light')
-rw-r--r--hicn-light/src/hicn/base/loop.c11
-rw-r--r--hicn-light/src/hicn/base/test/test-loop.cc13
-rw-r--r--hicn-light/src/hicn/core/connection_table.h4
-rw-r--r--hicn-light/src/hicn/core/listener_table.h4
4 files changed, 15 insertions, 17 deletions
diff --git a/hicn-light/src/hicn/base/loop.c b/hicn-light/src/hicn/base/loop.c
index 6e477f85a..8588b538d 100644
--- a/hicn-light/src/hicn/base/loop.c
+++ b/hicn-light/src/hicn/base/loop.c
@@ -92,11 +92,14 @@ ERR_MALLOC:
return NULL;
}
-void loop_free(loop_t *loop) { event_base_free(loop->event_base); }
+void loop_free(loop_t *loop) {
+ event_base_free(loop->event_base);
+ free(loop);
+}
int loop_dispatch(loop_t *loop)
{
- event_base_loop(loop->event_base, 0);
+ event_base_loop(loop->event_base, EVLOOP_NO_EXIT_ON_EMPTY);
return 0;
}
@@ -201,7 +204,7 @@ int loop_timer_is_enabled(event_t *timer)
int loop_event_free(event_t *event)
{
- loop_event_unregister(event);
+ int ret = loop_event_unregister(event);
free(event);
- return 0;
+ return ret;
}
diff --git a/hicn-light/src/hicn/base/test/test-loop.cc b/hicn-light/src/hicn/base/test/test-loop.cc
index 44684ef0e..c86ccd5e6 100644
--- a/hicn-light/src/hicn/base/test/test-loop.cc
+++ b/hicn-light/src/hicn/base/test/test-loop.cc
@@ -175,15 +175,10 @@ class LoopTest : public ::testing::Test {
char buffer[BUFFER_SIZE];
};
-TEST_F(LoopTest, LoopCreate)
+TEST_F(LoopTest, LoopCreateAndFree)
{
loop_ = loop_create();
EXPECT_TRUE(loop_ != NULL);
-}
-
-TEST_F(LoopTest, LoopFree)
-{
- loop_ = loop_create();
loop_free (loop_);
EXPECT_TRUE(loop_ != NULL);
}
@@ -205,7 +200,7 @@ TEST_F(LoopTest, EventCreateAndFree)
EXPECT_TRUE(ret >= 0);
// Unregister the event
- ret = loop_event_unregister(event_);
+ ret = loop_event_free(event_);
EXPECT_TRUE(ret >= 0);
// Free event loop
@@ -239,8 +234,8 @@ TEST_F(LoopTest, TimerCreateAndCancel)
loop_undispatch(loop_);
// Unregister the events
- ret = loop_event_unregister(timer_);
- ret += loop_event_unregister(timer2);
+ ret = loop_event_free(timer_);
+ ret += loop_event_free(timer2);
EXPECT_TRUE(ret >= 0);
// Free event loop
diff --git a/hicn-light/src/hicn/core/connection_table.h b/hicn-light/src/hicn/core/connection_table.h
index d32a5fee8..160867176 100644
--- a/hicn-light/src/hicn/core/connection_table.h
+++ b/hicn-light/src/hicn/core/connection_table.h
@@ -43,8 +43,8 @@
#define address_pair_hash_eq(a, b) (address_pair_hash(b) - address_pair_hash(a))
/* Hash table types for indices. */
-KHASH_INIT(ct_pair, const address_pair_t *, unsigned, 0, address_pair_hash, address_pair_hash_eq);
-KHASH_INIT(ct_name, const char *, unsigned, 0, str_hash, str_hash_eq);
+KHASH_INIT(ct_pair, const address_pair_t *, unsigned, 1, address_pair_hash, address_pair_hash_eq);
+KHASH_MAP_INIT_STR(ct_name, unsigned);
typedef struct {
size_t max_size;
diff --git a/hicn-light/src/hicn/core/listener_table.h b/hicn-light/src/hicn/core/listener_table.h
index 5824f0551..91b68ee94 100644
--- a/hicn-light/src/hicn/core/listener_table.h
+++ b/hicn-light/src/hicn/core/listener_table.h
@@ -44,8 +44,8 @@
#define key_hash_eq(a, b) (key_hash(b) - key_hash(a))
/* Hash table types for indices */
-KHASH_INIT(lt_name, const char *, unsigned, 0, str_hash, str_hash_eq);
-KHASH_INIT(lt_key, listener_key_t *, unsigned, 0, key_hash, key_hash_eq);
+KHASH_MAP_INIT_STR(lt_name, unsigned);
+KHASH_INIT(lt_key, listener_key_t *, unsigned, 1, key_hash, key_hash_eq);
typedef struct {
size_t max_size;