diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-08-25 07:45:09 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-09-05 15:12:14 -0700 |
| commit | e87afc8c0624304411ecd5bc3ee8525a53aefa1f (patch) | |
| tree | 2f8af8ed6c95f448809ca5e0fa702a7ea43dcf09 | |
| parent | 5a6c4003663955744385ea1c7b36e0b908ffe2d1 (diff) | |
| download | nng-e87afc8c0624304411ecd5bc3ee8525a53aefa1f.tar.gz nng-e87afc8c0624304411ecd5bc3ee8525a53aefa1f.tar.bz2 nng-e87afc8c0624304411ecd5bc3ee8525a53aefa1f.zip | |
Allow forcibly adding idhash values outside of the range.
This will allow us to use idhash to manage ephemeral ports (indexed
by port), while also allowing us to insert managed ports.
| -rw-r--r-- | src/core/idhash.c | 13 | ||||
| -rw-r--r-- | tests/idhash.c | 19 |
2 files changed, 6 insertions, 26 deletions
diff --git a/src/core/idhash.c b/src/core/idhash.c index c0030f76..8651a3d6 100644 --- a/src/core/idhash.c +++ b/src/core/idhash.c @@ -246,10 +246,6 @@ nni_hash_insert(nni_idhash *h, uint64_t id, void *val) { size_t index; - if ((id < h->ih_minval) || (id > h->ih_maxval)) { - return (NNG_EINVAL); - } - // Try to resize. If we can't, but we still have room, go ahead // and store it. if ((nni_hash_resize(h) != 0) && (h->ih_count >= (h->ih_cap - 1))) { @@ -270,15 +266,6 @@ nni_hash_insert(nni_idhash *h, uint64_t id, void *val) ent->ihe_skips++; index = NNI_IDHASH_NEXTPROBE(h, index); } - - // If this was the old dynamic value, just bump it. - if (h->ih_dynval == id) { - h->ih_dynval++; - // Roll over... - if (h->ih_dynval == h->ih_maxval) { - h->ih_dynval = h->ih_minval; - } - } } int diff --git a/tests/idhash.c b/tests/idhash.c index 21f66c58..e4183e98 100644 --- a/tests/idhash.c +++ b/tests/idhash.c @@ -83,14 +83,6 @@ Main({ So(ptr == NULL); }); - Convey("Range checks work", { - char *bad = "bad"; - - nni_idhash_set_limits(h, 1, 10, 1); - So(nni_idhash_insert(h, 20, bad) == - NNG_EINVAL); - }); - Convey("64-bit hash values work", { char * huge = "huge"; void * ptr = NULL; @@ -175,11 +167,12 @@ Main({ So(id == 11); }); }); - Convey("We cannot insert bogus values", { - So(nni_idhash_insert(h, 1, &expect[0]) == - NNG_EINVAL); - So(nni_idhash_insert(h, 100, &expect[0]) == - NNG_EINVAL); + Convey("We can insert outside range forcibly", { + So(nni_idhash_insert(h, 1, &expect[0]) == 0); + So(nni_idhash_insert(h, 100, &expect[0]) == 0); + So(nni_idhash_alloc(h, &id, &expect[1]) == 0); + So(id >= 10); + So(id <= 13); }); }); }); |
