aboutsummaryrefslogtreecommitdiff
path: root/src/protocol/survey
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-24 14:15:48 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-24 14:20:34 -0700
commitc9a68bfe6bea2acc708bf49045f6cb65017a3306 (patch)
treee2b93b81b2962bdfb7953cb30fcfae08f0bd4093 /src/protocol/survey
parent68ff9c823d3cead2b11a003c40c8f5affc11dc71 (diff)
downloadnng-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/survey')
-rw-r--r--src/protocol/survey/respond.c24
-rw-r--r--src/protocol/survey/survey.c24
2 files changed, 16 insertions, 32 deletions
diff --git a/src/protocol/survey/respond.c b/src/protocol/survey/respond.c
index a097f551..e695a987 100644
--- a/src/protocol/survey/respond.c
+++ b/src/protocol/survey/respond.c
@@ -348,14 +348,13 @@ static int
nni_resp_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
{
nni_resp_sock *psock = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
int oldraw;
- switch (opt) {
- case NNG_OPT_MAXTTL:
+ if (opt == nng_optid_maxttl) {
rv = nni_setopt_int(&psock->ttl, buf, sz, 1, 255);
- break;
- case NNG_OPT_RAW:
+
+ } else if (opt == nng_optid_raw) {
oldraw = psock->raw;
rv = nni_setopt_int(&psock->raw, buf, sz, 0, 1);
if (oldraw != psock->raw) {
@@ -365,10 +364,8 @@ nni_resp_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
nni_sock_senderr(psock->nsock, NNG_ESTATE);
}
}
- break;
- default:
- rv = NNG_ENOTSUP;
}
+
return (rv);
}
@@ -376,17 +373,12 @@ static int
nni_resp_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
{
nni_resp_sock *psock = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
- switch (opt) {
- case NNG_OPT_MAXTTL:
+ if (opt == nng_optid_maxttl) {
rv = nni_getopt_int(&psock->ttl, buf, szp);
- break;
- case NNG_OPT_RAW:
+ } else if (opt == nng_optid_raw) {
rv = nni_getopt_int(&psock->raw, buf, szp);
- break;
- default:
- rv = NNG_ENOTSUP;
}
return (rv);
}
diff --git a/src/protocol/survey/survey.c b/src/protocol/survey/survey.c
index 2a32f289..d7341025 100644
--- a/src/protocol/survey/survey.c
+++ b/src/protocol/survey/survey.c
@@ -267,14 +267,13 @@ static int
nni_surv_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
{
nni_surv_sock *psock = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
int oldraw;
- switch (opt) {
- case NNG_OPT_SURVEYTIME:
+ if (opt == nng_optid_surveyor_surveytime) {
rv = nni_setopt_usec(&psock->survtime, buf, sz);
- break;
- case NNG_OPT_RAW:
+
+ } else if (opt == nng_optid_raw) {
oldraw = psock->raw;
rv = nni_setopt_int(&psock->raw, buf, sz, 0, 1);
if (oldraw != psock->raw) {
@@ -286,10 +285,8 @@ nni_surv_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
psock->survid = 0;
nni_timer_cancel(&psock->timer);
}
- break;
- default:
- rv = NNG_ENOTSUP;
}
+
return (rv);
}
@@ -297,17 +294,12 @@ static int
nni_surv_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
{
nni_surv_sock *psock = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
- switch (opt) {
- case NNG_OPT_SURVEYTIME:
+ if (opt == nng_optid_surveyor_surveytime) {
rv = nni_getopt_usec(&psock->survtime, buf, szp);
- break;
- case NNG_OPT_RAW:
+ } else if (opt == nng_optid_raw) {
rv = nni_getopt_int(&psock->raw, buf, szp);
- break;
- default:
- rv = NNG_ENOTSUP;
}
return (rv);
}