aboutsummaryrefslogtreecommitdiff
path: root/src/protocol/pair
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-23 11:23:22 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-23 21:14:12 -0700
commit8ad296769192cf4628710ac0b228be2aca6d8dad (patch)
treeedd6240a63cc3b2a7e6206e1cc07b5c5edb9f1bf /src/protocol/pair
parent7074c5c50936308d1ef58be4ce1ca5e776e4c8cb (diff)
downloadnng-8ad296769192cf4628710ac0b228be2aca6d8dad.tar.gz
nng-8ad296769192cf4628710ac0b228be2aca6d8dad.tar.bz2
nng-8ad296769192cf4628710ac0b228be2aca6d8dad.zip
Implement dynamic option numbering.
This permits option numbers to be allocated based on string name. Eventually all the option values will be replaced with option names. This will facilitate transports (ZeroTier) that may need further options.
Diffstat (limited to 'src/protocol/pair')
-rw-r--r--src/protocol/pair/pair_v1.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/src/protocol/pair/pair_v1.c b/src/protocol/pair/pair_v1.c
index 2b8a9120..09543830 100644
--- a/src/protocol/pair/pair_v1.c
+++ b/src/protocol/pair/pair_v1.c
@@ -69,6 +69,7 @@ pair1_sock_init(void **sp, nni_sock *nsock)
{
pair1_sock *s;
int rv;
+ int poly;
if ((s = NNI_ALLOC_STRUCT(s)) == NULL) {
return (NNG_ENOMEM);
@@ -83,6 +84,11 @@ pair1_sock_init(void **sp, nni_sock *nsock)
nni_aio_init(&s->aio_getq, pair1_sock_getq_cb, s);
nni_mtx_init(&s->mtx);
+ if ((rv = nni_option_register("polyamorous", &poly)) != 0) {
+ pair1_sock_fini(s);
+ return (rv);
+ }
+
s->nsock = nsock;
s->raw = 0;
s->poly = 0;
@@ -393,30 +399,30 @@ pair1_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
pair1_sock *s = arg;
int rv;
- nni_mtx_lock(&s->mtx);
- switch (opt) {
- case NNG_OPT_RAW:
+ if (opt == nni_option_lookup("raw")) {
+ nni_mtx_lock(&s->mtx);
if (s->started) {
rv = NNG_ESTATE;
} else {
rv = nni_setopt_int(&s->raw, buf, sz, 0, 1);
}
- break;
- case NNG_OPT_POLYAMOROUS:
+ nni_mtx_unlock(&s->mtx);
+ } else if (opt == nni_option_lookup("polyamorous")) {
+ nni_mtx_lock(&s->mtx);
if (s->started) {
rv = NNG_ESTATE;
} else {
rv = nni_setopt_int(&s->poly, buf, sz, 0, 1);
}
- break;
- case NNG_OPT_MAXTTL:
+ nni_mtx_unlock(&s->mtx);
+ } else if (opt == nni_option_lookup("max-ttl")) {
+ nni_mtx_lock(&s->mtx);
rv = nni_setopt_int(&s->ttl, buf, sz, 1, 255);
- break;
- default:
+ nni_mtx_unlock(&s->mtx);
+ } else {
rv = NNG_ENOTSUP;
}
- nni_mtx_unlock(&s->mtx);
return (rv);
}
@@ -426,21 +432,21 @@ pair1_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
pair1_sock *s = arg;
int rv;
- nni_mtx_lock(&s->mtx);
- switch (opt) {
- case NNG_OPT_RAW:
+ if (opt == nni_option_lookup("raw")) {
+ nni_mtx_lock(&s->mtx);
rv = nni_getopt_int(&s->raw, buf, szp);
- break;
- case NNG_OPT_MAXTTL:
+ nni_mtx_unlock(&s->mtx);
+ } else if (opt == nni_option_lookup("max-ttl")) {
+ nni_mtx_lock(&s->mtx);
rv = nni_getopt_int(&s->ttl, buf, szp);
- break;
- case NNG_OPT_POLYAMOROUS:
+ nni_mtx_unlock(&s->mtx);
+ } else if (opt == nni_option_lookup("polyamorous")) {
+ nni_mtx_lock(&s->mtx);
rv = nni_getopt_int(&s->poly, buf, szp);
- break;
- default:
+ nni_mtx_unlock(&s->mtx);
+ } else {
rv = NNG_ENOTSUP;
}
- nni_mtx_unlock(&s->mtx);
return (rv);
}