diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-08-24 14:15:48 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-08-24 14:20:34 -0700 |
| commit | c9a68bfe6bea2acc708bf49045f6cb65017a3306 (patch) | |
| tree | e2b93b81b2962bdfb7953cb30fcfae08f0bd4093 /src/protocol/pair/pair_v1.c | |
| parent | 68ff9c823d3cead2b11a003c40c8f5affc11dc71 (diff) | |
| download | nng-c9a68bfe6bea2acc708bf49045f6cb65017a3306.tar.gz nng-c9a68bfe6bea2acc708bf49045f6cb65017a3306.tar.bz2 nng-c9a68bfe6bea2acc708bf49045f6cb65017a3306.zip | |
Eliminate legacy option settings, provide easier option IDs.
This eliminates all the old #define's or enum values, making all
option IDs now totally dynamic, and providing well-known string
values for well-behaved applications.
We have added tests of some of these options, including lookups, and
so forth. We have also fixed a few problems; including at least
one crasher bug when the timeouts on reconnect were zero.
Protocol specific options are now handled in the protocol. We will
be moving the initialization for a few of those well known entities
to the protocol startup code, following the PAIRv1 pattern, later.
Applications must therefore not depend on the value of the integer IDs,
at least until the application has opened a socket of the appropriate
type.
Diffstat (limited to 'src/protocol/pair/pair_v1.c')
| -rw-r--r-- | src/protocol/pair/pair_v1.c | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/src/protocol/pair/pair_v1.c b/src/protocol/pair/pair_v1.c index 3b6770ba..a737402f 100644 --- a/src/protocol/pair/pair_v1.c +++ b/src/protocol/pair/pair_v1.c @@ -25,9 +25,9 @@ static void pair1_pipe_getq_cb(void *); static void pair1_pipe_putq_cb(void *); static void pair1_pipe_fini(void *); -static int pair1_opt_poly = -1; -static int pair1_opt_maxttl = -1; -static int pair1_opt_raw = -1; +// These are exposed as external names for external consumers. +int nng_optid_pair1_poly; +const char *nng_opt_pair1_poly = "pair1-polyamorous"; // pair1_sock is our per-socket protocol private structure. struct pair1_sock { @@ -400,10 +400,10 @@ pair1_sock_close(void *arg) static int pair1_sock_setopt(void *arg, int opt, const void *buf, size_t sz) { - pair1_sock *s = arg; - int rv; + pair1_sock *s = arg; + int rv = NNG_ENOTSUP; - if (opt == pair1_opt_raw) { + if (opt == nng_optid_raw) { nni_mtx_lock(&s->mtx); if (s->started) { rv = NNG_ESTATE; @@ -411,7 +411,11 @@ pair1_sock_setopt(void *arg, int opt, const void *buf, size_t sz) rv = nni_setopt_int(&s->raw, buf, sz, 0, 1); } nni_mtx_unlock(&s->mtx); - } else if (opt == pair1_opt_poly) { + } else if (opt == nng_optid_maxttl) { + nni_mtx_lock(&s->mtx); + rv = nni_setopt_int(&s->ttl, buf, sz, 1, 255); + nni_mtx_unlock(&s->mtx); + } else if (opt == nng_optid_pair1_poly) { nni_mtx_lock(&s->mtx); if (s->started) { rv = NNG_ESTATE; @@ -419,12 +423,6 @@ pair1_sock_setopt(void *arg, int opt, const void *buf, size_t sz) rv = nni_setopt_int(&s->poly, buf, sz, 0, 1); } nni_mtx_unlock(&s->mtx); - } else if (opt == pair1_opt_maxttl) { - nni_mtx_lock(&s->mtx); - rv = nni_setopt_int(&s->ttl, buf, sz, 1, 255); - nni_mtx_unlock(&s->mtx); - } else { - rv = NNG_ENOTSUP; } return (rv); @@ -433,23 +431,21 @@ pair1_sock_setopt(void *arg, int opt, const void *buf, size_t sz) static int pair1_sock_getopt(void *arg, int opt, void *buf, size_t *szp) { - pair1_sock *s = arg; - int rv; + pair1_sock *s = arg; + int rv = NNG_ENOTSUP; - if (opt == pair1_opt_raw) { + if (opt == nng_optid_raw) { nni_mtx_lock(&s->mtx); rv = nni_getopt_int(&s->raw, buf, szp); nni_mtx_unlock(&s->mtx); - } else if (opt == pair1_opt_maxttl) { + } else if (opt == nng_optid_maxttl) { nni_mtx_lock(&s->mtx); rv = nni_getopt_int(&s->ttl, buf, szp); nni_mtx_unlock(&s->mtx); - } else if (opt == pair1_opt_poly) { + } else if (opt == nng_optid_pair1_poly) { nni_mtx_lock(&s->mtx); rv = nni_getopt_int(&s->poly, buf, szp); nni_mtx_unlock(&s->mtx); - } else { - rv = NNG_ENOTSUP; } return (rv); } @@ -457,19 +453,15 @@ pair1_sock_getopt(void *arg, int opt, void *buf, size_t *szp) static void pair1_fini(void) { - pair1_opt_poly = -1; - pair1_opt_raw = -1; - pair1_opt_maxttl = -1; + nng_optid_pair1_poly = -1; } static int pair1_init(void) { int rv; - if (((rv = nni_option_register("polyamorous", &pair1_opt_poly)) != - 0) || - ((rv = nni_option_register("raw", &pair1_opt_raw)) != 0) || - ((rv = nni_option_register("max-ttl", &pair1_opt_maxttl)) != 0)) { + if ((rv = nni_option_register( + nng_opt_pair1_poly, &nng_optid_pair1_poly)) != 0) { pair1_fini(); return (rv); } |
