aboutsummaryrefslogtreecommitdiff
path: root/src/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocol')
-rw-r--r--src/protocol/bus/bus.c16
-rw-r--r--src/protocol/pair/pair_v0.c12
-rw-r--r--src/protocol/pair/pair_v1.c46
-rw-r--r--src/protocol/pipeline/pull.c16
-rw-r--r--src/protocol/pipeline/push.c16
-rw-r--r--src/protocol/pubsub/pub.c16
-rw-r--r--src/protocol/pubsub/sub.c22
-rw-r--r--src/protocol/reqrep/rep.c22
-rw-r--r--src/protocol/reqrep/req.c34
-rw-r--r--src/protocol/survey/respond.c24
-rw-r--r--src/protocol/survey/survey.c24
11 files changed, 81 insertions, 167 deletions
diff --git a/src/protocol/bus/bus.c b/src/protocol/bus/bus.c
index 88fd93e0..6f6def0a 100644
--- a/src/protocol/bus/bus.c
+++ b/src/protocol/bus/bus.c
@@ -322,14 +322,10 @@ static int
nni_bus_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
{
nni_bus_sock *psock = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
- switch (opt) {
- case NNG_OPT_RAW:
+ if (opt == nng_optid_raw) {
rv = nni_setopt_int(&psock->raw, buf, sz, 0, 1);
- break;
- default:
- rv = NNG_ENOTSUP;
}
return (rv);
}
@@ -338,14 +334,10 @@ static int
nni_bus_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
{
nni_bus_sock *psock = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
- switch (opt) {
- case NNG_OPT_RAW:
+ 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/pair/pair_v0.c b/src/protocol/pair/pair_v0.c
index acf9ec25..ef420051 100644
--- a/src/protocol/pair/pair_v0.c
+++ b/src/protocol/pair/pair_v0.c
@@ -231,11 +231,9 @@ pair0_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
pair0_sock *s = arg;
int rv;
- switch (opt) {
- case NNG_OPT_RAW:
+ if (opt == nng_optid_raw) {
rv = nni_setopt_int(&s->raw, buf, sz, 0, 1);
- break;
- default:
+ } else {
rv = NNG_ENOTSUP;
}
return (rv);
@@ -247,11 +245,9 @@ pair0_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
pair0_sock *s = arg;
int rv;
- switch (opt) {
- case NNG_OPT_RAW:
+ if (opt == nng_optid_raw) {
rv = nni_getopt_int(&s->raw, buf, szp);
- break;
- default:
+ } else {
rv = NNG_ENOTSUP;
}
return (rv);
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);
}
diff --git a/src/protocol/pipeline/pull.c b/src/protocol/pipeline/pull.c
index 1ebcc4a2..1d738ec2 100644
--- a/src/protocol/pipeline/pull.c
+++ b/src/protocol/pipeline/pull.c
@@ -170,14 +170,10 @@ static int
nni_pull_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
{
nni_pull_sock *pull = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
- switch (opt) {
- case NNG_OPT_RAW:
+ if (opt == nng_optid_raw) {
rv = nni_setopt_int(&pull->raw, buf, sz, 0, 1);
- break;
- default:
- rv = NNG_ENOTSUP;
}
return (rv);
}
@@ -186,14 +182,10 @@ static int
nni_pull_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
{
nni_pull_sock *pull = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
- switch (opt) {
- case NNG_OPT_RAW:
+ if (opt == nng_optid_raw) {
rv = nni_getopt_int(&pull->raw, buf, szp);
- break;
- default:
- rv = NNG_ENOTSUP;
}
return (rv);
}
diff --git a/src/protocol/pipeline/push.c b/src/protocol/pipeline/push.c
index 1bc1659c..10d04091 100644
--- a/src/protocol/pipeline/push.c
+++ b/src/protocol/pipeline/push.c
@@ -192,14 +192,10 @@ static int
nni_push_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
{
nni_push_sock *push = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
- switch (opt) {
- case NNG_OPT_RAW:
+ if (opt == nng_optid_raw) {
rv = nni_setopt_int(&push->raw, buf, sz, 0, 1);
- break;
- default:
- rv = NNG_ENOTSUP;
}
return (rv);
}
@@ -208,14 +204,10 @@ static int
nni_push_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
{
nni_push_sock *push = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
- switch (opt) {
- case NNG_OPT_RAW:
+ if (opt == nng_optid_raw) {
rv = nni_getopt_int(&push->raw, buf, szp);
- break;
- default:
- rv = NNG_ENOTSUP;
}
return (rv);
}
diff --git a/src/protocol/pubsub/pub.c b/src/protocol/pubsub/pub.c
index 940f2139..bbca1ecd 100644
--- a/src/protocol/pubsub/pub.c
+++ b/src/protocol/pubsub/pub.c
@@ -266,14 +266,10 @@ static int
nni_pub_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
{
nni_pub_sock *pub = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
- switch (opt) {
- case NNG_OPT_RAW:
+ if (opt == nng_optid_raw) {
rv = nni_setopt_int(&pub->raw, buf, sz, 0, 1);
- break;
- default:
- rv = NNG_ENOTSUP;
}
return (rv);
}
@@ -282,14 +278,10 @@ static int
nni_pub_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
{
nni_pub_sock *pub = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
- switch (opt) {
- case NNG_OPT_RAW:
+ if (opt == nng_optid_raw) {
rv = nni_getopt_int(&pub->raw, buf, szp);
- break;
- default:
- rv = NNG_ENOTSUP;
}
return (rv);
}
diff --git a/src/protocol/pubsub/sub.c b/src/protocol/pubsub/sub.c
index 78b9d157..0563b764 100644
--- a/src/protocol/pubsub/sub.c
+++ b/src/protocol/pubsub/sub.c
@@ -251,20 +251,14 @@ static int
nni_sub_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
{
nni_sub_sock *sub = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
- switch (opt) {
- case NNG_OPT_RAW:
+ if (opt == nng_optid_raw) {
rv = nni_setopt_int(&sub->raw, buf, sz, 0, 1);
- break;
- case NNG_OPT_SUBSCRIBE:
+ } else if (opt == nng_optid_sub_subscribe) {
rv = nni_sub_subscribe(sub, buf, sz);
- break;
- case NNG_OPT_UNSUBSCRIBE:
+ } else if (opt == nng_optid_sub_unsubscribe) {
rv = nni_sub_unsubscribe(sub, buf, sz);
- break;
- default:
- rv = NNG_ENOTSUP;
}
return (rv);
}
@@ -273,14 +267,10 @@ static int
nni_sub_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
{
nni_sub_sock *sub = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
- switch (opt) {
- case NNG_OPT_RAW:
+ if (opt == nng_optid_raw) {
rv = nni_getopt_int(&sub->raw, buf, szp);
- break;
- default:
- rv = NNG_ENOTSUP;
}
return (rv);
}
diff --git a/src/protocol/reqrep/rep.c b/src/protocol/reqrep/rep.c
index 09f2b285..cd33d019 100644
--- a/src/protocol/reqrep/rep.c
+++ b/src/protocol/reqrep/rep.c
@@ -348,18 +348,13 @@ static int
nni_rep_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
{
nni_rep_sock *rep = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
- switch (opt) {
- case NNG_OPT_MAXTTL:
+ if (opt == nng_optid_maxttl) {
rv = nni_setopt_int(&rep->ttl, buf, sz, 1, 255);
- break;
- case NNG_OPT_RAW:
+ } else if (opt == nng_optid_raw) {
rv = nni_setopt_int(&rep->raw, buf, sz, 0, 1);
nni_sock_senderr(rep->sock, rep->raw ? 0 : NNG_ESTATE);
- break;
- default:
- rv = NNG_ENOTSUP;
}
return (rv);
}
@@ -368,17 +363,12 @@ static int
nni_rep_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
{
nni_rep_sock *rep = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
- switch (opt) {
- case NNG_OPT_MAXTTL:
+ if (opt == nng_optid_maxttl) {
rv = nni_getopt_int(&rep->ttl, buf, szp);
- break;
- case NNG_OPT_RAW:
+ } else if (opt == nng_optid_raw) {
rv = nni_getopt_int(&rep->raw, buf, szp);
- break;
- default:
- rv = NNG_ENOTSUP;
}
return (rv);
}
diff --git a/src/protocol/reqrep/req.c b/src/protocol/reqrep/req.c
index bab81331..2579417a 100644
--- a/src/protocol/reqrep/req.c
+++ b/src/protocol/reqrep/req.c
@@ -243,24 +243,21 @@ static int
nni_req_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
{
nni_req_sock *req = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
- switch (opt) {
- case NNG_OPT_RESENDTIME:
+ if (opt == nng_optid_req_resendtime) {
rv = nni_setopt_usec(&req->retry, buf, sz);
- break;
- case NNG_OPT_RAW:
+
+ } else if (opt == nng_optid_raw) {
rv = nni_setopt_int(&req->raw, buf, sz, 0, 1);
if (rv == 0) {
nni_sock_recverr(req->sock, req->raw ? 0 : NNG_ESTATE);
}
- break;
- case NNG_OPT_MAXTTL:
+
+ } else if (opt == nng_optid_maxttl) {
rv = nni_setopt_int(&req->ttl, buf, sz, 1, 255);
- break;
- default:
- rv = NNG_ENOTSUP;
}
+
return (rv);
}
@@ -268,21 +265,18 @@ static int
nni_req_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
{
nni_req_sock *req = arg;
- int rv;
+ int rv = NNG_ENOTSUP;
- switch (opt) {
- case NNG_OPT_RESENDTIME:
+ if (opt == nng_optid_req_resendtime) {
rv = nni_getopt_usec(&req->retry, buf, szp);
- break;
- case NNG_OPT_RAW:
+
+ } else if (opt == nng_optid_raw) {
rv = nni_getopt_int(&req->raw, buf, szp);
- break;
- case NNG_OPT_MAXTTL:
+
+ } else if (opt == nng_optid_maxttl) {
rv = nni_getopt_int(&req->ttl, buf, szp);
- break;
- default:
- rv = NNG_ENOTSUP;
}
+
return (rv);
}
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);
}