2020-01-09 16:52:25 +00:00
|
|
|
/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc. See LICENSE. */
|
2017-09-22 21:00:03 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/queue.h>
|
2018-03-12 22:25:01 +00:00
|
|
|
#ifndef WIN32
|
2017-09-22 21:00:03 +00:00
|
|
|
#include <unistd.h>
|
2018-03-12 22:25:01 +00:00
|
|
|
#endif
|
2017-09-22 21:00:03 +00:00
|
|
|
|
|
|
|
#include "lsquic.h"
|
|
|
|
#include "lsquic_int_types.h"
|
|
|
|
#include "lsquic_types.h"
|
2019-09-11 15:27:58 +00:00
|
|
|
#include "lsquic_hash.h"
|
2017-09-22 21:00:03 +00:00
|
|
|
#include "lsquic_conn.h"
|
|
|
|
#include "lsquic_conn_hash.h"
|
|
|
|
#include "lsquic_mm.h"
|
|
|
|
#include "lsquic_malo.h"
|
|
|
|
#include "lsquic_logger.h"
|
|
|
|
#include "lsquic.h"
|
|
|
|
|
|
|
|
|
|
|
|
static struct lsquic_conn *
|
|
|
|
get_new_lsquic_conn (struct malo *malo)
|
|
|
|
{
|
|
|
|
struct lsquic_conn *lconn = lsquic_malo_get(malo);
|
|
|
|
memset(lconn, 0, sizeof(*lconn));
|
2019-09-11 15:27:58 +00:00
|
|
|
memcpy(lconn->cn_cid.idbuf, &lconn, sizeof(lconn));
|
|
|
|
lconn->cn_cid.len = sizeof(lconn);
|
2017-09-22 21:00:03 +00:00
|
|
|
return lconn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct malo *malo;
|
|
|
|
struct conn_hash conn_hash;
|
2018-02-28 19:25:21 +00:00
|
|
|
unsigned n, nelems;
|
2017-09-22 21:00:03 +00:00
|
|
|
struct lsquic_conn *lconn, *find_lsconn;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
if (argc > 1)
|
|
|
|
nelems = atoi(argv[1]);
|
|
|
|
else
|
|
|
|
nelems = 1000000;
|
|
|
|
|
|
|
|
lsquic_log_to_fstream(stderr, LLTS_HHMMSSMS);
|
|
|
|
lsquic_set_log_level("info");
|
|
|
|
|
|
|
|
malo = lsquic_malo_create(sizeof(*lconn));
|
2018-06-13 15:10:28 +00:00
|
|
|
s = conn_hash_init(&conn_hash, 0);
|
2017-09-22 21:00:03 +00:00
|
|
|
assert(0 == s);
|
|
|
|
|
|
|
|
for (n = 0; n < nelems; ++n)
|
|
|
|
{
|
|
|
|
lconn = get_new_lsquic_conn(malo);
|
|
|
|
lconn->cn_if = (void *) (uintptr_t) n; /* This will be used for verification later the test */
|
2019-09-11 15:27:58 +00:00
|
|
|
find_lsconn = conn_hash_find_by_cid(&conn_hash, &lconn->cn_cid);
|
2017-09-22 21:00:03 +00:00
|
|
|
assert(!find_lsconn);
|
2018-02-28 19:25:21 +00:00
|
|
|
s = conn_hash_add(&conn_hash, lconn);
|
2017-09-22 21:00:03 +00:00
|
|
|
assert(0 == s);
|
2019-01-30 20:28:35 +00:00
|
|
|
lconn->cn_flags = 1; /* In hash */
|
2017-09-22 21:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(nelems == conn_hash_count(&conn_hash));
|
|
|
|
|
|
|
|
for (lconn = lsquic_malo_first(malo); lconn;
|
|
|
|
lconn = lsquic_malo_next(malo))
|
|
|
|
{
|
2019-01-30 20:28:35 +00:00
|
|
|
assert(lconn->cn_flags == 1);
|
2019-09-11 15:27:58 +00:00
|
|
|
find_lsconn = conn_hash_find_by_cid(&conn_hash, &lconn->cn_cid);
|
2017-09-22 21:00:03 +00:00
|
|
|
assert(find_lsconn == lconn);
|
|
|
|
conn_hash_remove(&conn_hash, lconn);
|
2019-01-30 20:28:35 +00:00
|
|
|
lconn->cn_flags = 0;
|
2019-09-11 15:27:58 +00:00
|
|
|
find_lsconn = conn_hash_find_by_cid(&conn_hash, &lconn->cn_cid);
|
2017-09-22 21:00:03 +00:00
|
|
|
assert(!find_lsconn);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(0 == conn_hash_count(&conn_hash));
|
|
|
|
|
|
|
|
conn_hash_cleanup(&conn_hash);
|
|
|
|
lsquic_malo_destroy(malo);
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|