summaryrefslogtreecommitdiff
path: root/src/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocol')
-rw-r--r--src/protocol/bus/bus.c43
-rw-r--r--src/protocol/pair/pair_v0.c43
-rw-r--r--src/protocol/pair/pair_v1.c128
-rw-r--r--src/protocol/pipeline/pull.c43
-rw-r--r--src/protocol/pipeline/push.c43
-rw-r--r--src/protocol/pubsub/pub.c43
-rw-r--r--src/protocol/pubsub/sub.c58
-rw-r--r--src/protocol/reqrep/rep.c56
-rw-r--r--src/protocol/reqrep/req.c88
-rw-r--r--src/protocol/survey/respond.c68
-rw-r--r--src/protocol/survey/survey.c72
11 files changed, 373 insertions, 312 deletions
diff --git a/src/protocol/bus/bus.c b/src/protocol/bus/bus.c
index d9189729..cad21989 100644
--- a/src/protocol/bus/bus.c
+++ b/src/protocol/bus/bus.c
@@ -325,27 +325,17 @@ bus_pipe_recv(bus_pipe *p)
}
static int
-bus_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
+bus_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
- bus_sock *s = arg;
- int rv = NNG_ENOTSUP;
-
- if (opt == nng_optid_raw) {
- rv = nni_setopt_int(&s->raw, buf, sz, 0, 1);
- }
- return (rv);
+ bus_sock *s = arg;
+ return (nni_setopt_int(&s->raw, buf, sz, 0, 1));
}
static int
-bus_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
+bus_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
- bus_sock *s = arg;
- int rv = NNG_ENOTSUP;
-
- if (opt == nng_optid_raw) {
- rv = nni_getopt_int(s->raw, buf, szp);
- }
- return (rv);
+ bus_sock *s = arg;
+ return (nni_getopt_int(s->raw, buf, szp));
}
static nni_proto_pipe_ops bus_pipe_ops = {
@@ -355,13 +345,22 @@ static nni_proto_pipe_ops bus_pipe_ops = {
.pipe_stop = bus_pipe_stop,
};
+static nni_proto_sock_option bus_sock_options[] = {
+ {
+ .pso_name = NNG_OPT_RAW,
+ .pso_getopt = bus_sock_getopt_raw,
+ .pso_setopt = bus_sock_setopt_raw,
+ },
+ // terminate list
+ { NULL, NULL, NULL },
+};
+
static nni_proto_sock_ops bus_sock_ops = {
- .sock_init = bus_sock_init,
- .sock_fini = bus_sock_fini,
- .sock_open = bus_sock_open,
- .sock_close = bus_sock_close,
- .sock_setopt = bus_sock_setopt,
- .sock_getopt = bus_sock_getopt,
+ .sock_init = bus_sock_init,
+ .sock_fini = bus_sock_fini,
+ .sock_open = bus_sock_open,
+ .sock_close = bus_sock_close,
+ .sock_options = bus_sock_options,
};
static nni_proto bus_proto = {
diff --git a/src/protocol/pair/pair_v0.c b/src/protocol/pair/pair_v0.c
index 277d5cb1..9cabe3c7 100644
--- a/src/protocol/pair/pair_v0.c
+++ b/src/protocol/pair/pair_v0.c
@@ -230,31 +230,17 @@ pair0_sock_close(void *arg)
}
static int
-pair0_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
+pair0_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
pair0_sock *s = arg;
- int rv;
-
- if (opt == nng_optid_raw) {
- rv = nni_setopt_int(&s->raw, buf, sz, 0, 1);
- } else {
- rv = NNG_ENOTSUP;
- }
- return (rv);
+ return (nni_setopt_int(&s->raw, buf, sz, 0, 1));
}
static int
-pair0_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
+pair0_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
pair0_sock *s = arg;
- int rv;
-
- if (opt == nng_optid_raw) {
- rv = nni_getopt_int(s->raw, buf, szp);
- } else {
- rv = NNG_ENOTSUP;
- }
- return (rv);
+ return (nni_getopt_int(s->raw, buf, szp));
}
static nni_proto_pipe_ops pair0_pipe_ops = {
@@ -264,13 +250,22 @@ static nni_proto_pipe_ops pair0_pipe_ops = {
.pipe_stop = pair0_pipe_stop,
};
+static nni_proto_sock_option pair0_sock_options[] = {
+ {
+ .pso_name = NNG_OPT_RAW,
+ .pso_getopt = pair0_sock_getopt_raw,
+ .pso_setopt = pair0_sock_setopt_raw,
+ },
+ // terminate list
+ { NULL, NULL, NULL },
+};
+
static nni_proto_sock_ops pair0_sock_ops = {
- .sock_init = pair0_sock_init,
- .sock_fini = pair0_sock_fini,
- .sock_open = pair0_sock_open,
- .sock_close = pair0_sock_close,
- .sock_setopt = pair0_sock_setopt,
- .sock_getopt = pair0_sock_getopt,
+ .sock_init = pair0_sock_init,
+ .sock_fini = pair0_sock_fini,
+ .sock_open = pair0_sock_open,
+ .sock_close = pair0_sock_close,
+ .sock_options = pair0_sock_options,
};
// Legacy protocol (v0)
diff --git a/src/protocol/pair/pair_v1.c b/src/protocol/pair/pair_v1.c
index 68dbc6f7..2cd5782b 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 *);
-// These are exposed as external names for external consumers.
-int nng_optid_pair1_poly;
-const char *nng_opt_pair1_poly = "pair1-polyamorous";
+// This is exposed as an external name for external consumers.
+#define NNG_OPT_PAIR1_POLY "pair1-polyamorous"
+const char *nng_opt_pair1_poly = NNG_OPT_PAIR1_POLY;
// pair1_sock is our per-socket protocol private structure.
struct pair1_sock {
@@ -394,74 +394,57 @@ pair1_sock_close(void *arg)
}
static int
-pair1_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
+pair1_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
- pair1_sock *s = arg;
- int rv = NNG_ENOTSUP;
-
- if (opt == nng_optid_raw) {
- nni_mtx_lock(&s->mtx);
- if (s->started) {
- rv = NNG_ESTATE;
- } else {
- rv = nni_setopt_int(&s->raw, buf, sz, 0, 1);
- }
- nni_mtx_unlock(&s->mtx);
- } 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;
- } else {
- rv = nni_setopt_int(&s->poly, buf, sz, 0, 1);
- }
- nni_mtx_unlock(&s->mtx);
- }
-
+ pair1_sock *s = arg;
+ int rv;
+ nni_mtx_lock(&s->mtx);
+ rv = s->started ? NNG_ESTATE : nni_setopt_int(&s->raw, buf, sz, 0, 1);
+ nni_mtx_unlock(&s->mtx);
return (rv);
}
static int
-pair1_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
+pair1_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
- pair1_sock *s = arg;
- int rv = NNG_ENOTSUP;
+ pair1_sock *s = arg;
+ return (nni_getopt_int(s->raw, buf, szp));
+}
- 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 == nng_optid_maxttl) {
- nni_mtx_lock(&s->mtx);
- rv = nni_getopt_int(s->ttl, buf, szp);
- nni_mtx_unlock(&s->mtx);
- } 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);
- }
+static int
+pair1_sock_setopt_maxttl(void *arg, const void *buf, size_t sz)
+{
+ pair1_sock *s = arg;
+ int rv;
+ nni_mtx_lock(&s->mtx); // Have to be locked against recv cb.
+ rv = nni_setopt_int(&s->ttl, buf, sz, 1, 255);
+ nni_mtx_unlock(&s->mtx);
return (rv);
}
-static void
-pair1_fini(void)
+static int
+pair1_sock_getopt_maxttl(void *arg, void *buf, size_t *szp)
{
- nng_optid_pair1_poly = -1;
+ pair1_sock *s = arg;
+ return (nni_getopt_int(s->ttl, buf, szp));
}
static int
-pair1_init(void)
+pair1_sock_setopt_poly(void *arg, const void *buf, size_t sz)
{
- int rv;
- if ((rv = nni_option_register(
- nng_opt_pair1_poly, &nng_optid_pair1_poly)) != 0) {
- pair1_fini();
- return (rv);
- }
- return (0);
+ pair1_sock *s = arg;
+ int rv;
+ nni_mtx_lock(&s->mtx);
+ rv = s->started ? NNG_ESTATE : nni_setopt_int(&s->poly, buf, sz, 0, 1);
+ nni_mtx_unlock(&s->mtx);
+ return (rv);
+}
+
+static int
+pair1_sock_getopt_poly(void *arg, void *buf, size_t *szp)
+{
+ pair1_sock *s = arg;
+ return (nni_getopt_int(s->poly, buf, szp));
}
static nni_proto_pipe_ops pair1_pipe_ops = {
@@ -471,13 +454,32 @@ static nni_proto_pipe_ops pair1_pipe_ops = {
.pipe_stop = pair1_pipe_stop,
};
+static nni_proto_sock_option pair1_sock_options[] = {
+ {
+ .pso_name = NNG_OPT_RAW,
+ .pso_getopt = pair1_sock_getopt_raw,
+ .pso_setopt = pair1_sock_setopt_raw,
+ },
+ {
+ .pso_name = NNG_OPT_MAXTTL,
+ .pso_getopt = pair1_sock_getopt_maxttl,
+ .pso_setopt = pair1_sock_setopt_maxttl,
+ },
+ {
+ .pso_name = NNG_OPT_PAIR1_POLY,
+ .pso_getopt = pair1_sock_getopt_poly,
+ .pso_setopt = pair1_sock_setopt_poly,
+ },
+ // terminate list
+ { NULL, NULL, NULL },
+};
+
static nni_proto_sock_ops pair1_sock_ops = {
- .sock_init = pair1_sock_init,
- .sock_fini = pair1_sock_fini,
- .sock_open = pair1_sock_open,
- .sock_close = pair1_sock_close,
- .sock_setopt = pair1_sock_setopt,
- .sock_getopt = pair1_sock_getopt,
+ .sock_init = pair1_sock_init,
+ .sock_fini = pair1_sock_fini,
+ .sock_open = pair1_sock_open,
+ .sock_close = pair1_sock_close,
+ .sock_options = pair1_sock_options,
};
static nni_proto pair1_proto = {
@@ -487,8 +489,6 @@ static nni_proto pair1_proto = {
.proto_flags = NNI_PROTO_FLAG_SNDRCV,
.proto_sock_ops = &pair1_sock_ops,
.proto_pipe_ops = &pair1_pipe_ops,
- .proto_init = &pair1_init,
- .proto_fini = &pair1_fini,
};
int
diff --git a/src/protocol/pipeline/pull.c b/src/protocol/pipeline/pull.c
index 21c1613d..ba828763 100644
--- a/src/protocol/pipeline/pull.c
+++ b/src/protocol/pipeline/pull.c
@@ -171,27 +171,17 @@ pull_sock_close(void *arg)
}
static int
-pull_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
+pull_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
- pull_sock *s = arg;
- int rv = NNG_ENOTSUP;
-
- if (opt == nng_optid_raw) {
- rv = nni_setopt_int(&s->raw, buf, sz, 0, 1);
- }
- return (rv);
+ pull_sock *s = arg;
+ return (nni_setopt_int(&s->raw, buf, sz, 0, 1));
}
static int
-pull_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
+pull_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
- pull_sock *s = arg;
- int rv = NNG_ENOTSUP;
-
- if (opt == nng_optid_raw) {
- rv = nni_getopt_int(s->raw, buf, szp);
- }
- return (rv);
+ pull_sock *s = arg;
+ return (nni_getopt_int(s->raw, buf, szp));
}
static nni_proto_pipe_ops pull_pipe_ops = {
@@ -201,13 +191,22 @@ static nni_proto_pipe_ops pull_pipe_ops = {
.pipe_stop = pull_pipe_stop,
};
+static nni_proto_sock_option pull_sock_options[] = {
+ {
+ .pso_name = NNG_OPT_RAW,
+ .pso_getopt = pull_sock_getopt_raw,
+ .pso_setopt = pull_sock_setopt_raw,
+ },
+ // terminate list
+ { NULL, NULL, NULL },
+};
+
static nni_proto_sock_ops pull_sock_ops = {
- .sock_init = pull_sock_init,
- .sock_fini = pull_sock_fini,
- .sock_open = pull_sock_open,
- .sock_close = pull_sock_close,
- .sock_setopt = pull_sock_setopt,
- .sock_getopt = pull_sock_getopt,
+ .sock_init = pull_sock_init,
+ .sock_fini = pull_sock_fini,
+ .sock_open = pull_sock_open,
+ .sock_close = pull_sock_close,
+ .sock_options = pull_sock_options,
};
static nni_proto pull_proto = {
diff --git a/src/protocol/pipeline/push.c b/src/protocol/pipeline/push.c
index b28f12c5..77db7fcb 100644
--- a/src/protocol/pipeline/push.c
+++ b/src/protocol/pipeline/push.c
@@ -192,27 +192,17 @@ push_getq_cb(void *arg)
}
static int
-push_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
+push_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
- push_sock *s = arg;
- int rv = NNG_ENOTSUP;
-
- if (opt == nng_optid_raw) {
- rv = nni_setopt_int(&s->raw, buf, sz, 0, 1);
- }
- return (rv);
+ push_sock *s = arg;
+ return (nni_setopt_int(&s->raw, buf, sz, 0, 1));
}
static int
-push_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
+push_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
- push_sock *s = arg;
- int rv = NNG_ENOTSUP;
-
- if (opt == nng_optid_raw) {
- rv = nni_getopt_int(s->raw, buf, szp);
- }
- return (rv);
+ push_sock *s = arg;
+ return (nni_getopt_int(s->raw, buf, szp));
}
static nni_proto_pipe_ops push_pipe_ops = {
@@ -222,13 +212,22 @@ static nni_proto_pipe_ops push_pipe_ops = {
.pipe_stop = push_pipe_stop,
};
+static nni_proto_sock_option push_sock_options[] = {
+ {
+ .pso_name = NNG_OPT_RAW,
+ .pso_getopt = push_sock_getopt_raw,
+ .pso_setopt = push_sock_setopt_raw,
+ },
+ // terminate list
+ { NULL, NULL, NULL },
+};
+
static nni_proto_sock_ops push_sock_ops = {
- .sock_init = push_sock_init,
- .sock_fini = push_sock_fini,
- .sock_open = push_sock_open,
- .sock_close = push_sock_close,
- .sock_setopt = push_sock_setopt,
- .sock_getopt = push_sock_getopt,
+ .sock_init = push_sock_init,
+ .sock_fini = push_sock_fini,
+ .sock_open = push_sock_open,
+ .sock_close = push_sock_close,
+ .sock_options = push_sock_options,
};
static nni_proto push_proto = {
diff --git a/src/protocol/pubsub/pub.c b/src/protocol/pubsub/pub.c
index 10a9760f..03f4603a 100644
--- a/src/protocol/pubsub/pub.c
+++ b/src/protocol/pubsub/pub.c
@@ -268,27 +268,17 @@ pub_pipe_send_cb(void *arg)
}
static int
-pub_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
+pub_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
- pub_sock *s = arg;
- int rv = NNG_ENOTSUP;
-
- if (opt == nng_optid_raw) {
- rv = nni_setopt_int(&s->raw, buf, sz, 0, 1);
- }
- return (rv);
+ pub_sock *s = arg;
+ return (nni_setopt_int(&s->raw, buf, sz, 0, 1));
}
static int
-pub_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
+pub_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
- pub_sock *s = arg;
- int rv = NNG_ENOTSUP;
-
- if (opt == nng_optid_raw) {
- rv = nni_getopt_int(s->raw, buf, szp);
- }
- return (rv);
+ pub_sock *s = arg;
+ return (nni_getopt_int(s->raw, buf, szp));
}
static nni_proto_pipe_ops pub_pipe_ops = {
@@ -298,13 +288,22 @@ static nni_proto_pipe_ops pub_pipe_ops = {
.pipe_stop = pub_pipe_stop,
};
+static nni_proto_sock_option pub_sock_options[] = {
+ {
+ .pso_name = NNG_OPT_RAW,
+ .pso_getopt = pub_sock_getopt_raw,
+ .pso_setopt = pub_sock_setopt_raw,
+ },
+ // terminate list
+ { NULL, NULL, NULL },
+};
+
static nni_proto_sock_ops pub_sock_ops = {
- .sock_init = pub_sock_init,
- .sock_fini = pub_sock_fini,
- .sock_open = pub_sock_open,
- .sock_close = pub_sock_close,
- .sock_setopt = pub_sock_setopt,
- .sock_getopt = pub_sock_getopt,
+ .sock_init = pub_sock_init,
+ .sock_fini = pub_sock_fini,
+ .sock_open = pub_sock_open,
+ .sock_close = pub_sock_close,
+ .sock_options = pub_sock_options,
};
static nni_proto pub_proto = {
diff --git a/src/protocol/pubsub/sub.c b/src/protocol/pubsub/sub.c
index 5f4b497d..7b6f4904 100644
--- a/src/protocol/pubsub/sub.c
+++ b/src/protocol/pubsub/sub.c
@@ -13,6 +13,9 @@
#include "core/nng_impl.h"
+const char *nng_opt_sub_subscribe = NNG_OPT_SUB_SUBSCRIBE;
+const char *nng_opt_sub_unsubscribe = NNG_OPT_SUB_UNSUBSCRIBE;
+
// Subscriber protocol. The SUB protocol receives messages sent to
// it from publishers, and filters out those it is not interested in,
// only passing up ones that match known subscriptions.
@@ -178,8 +181,9 @@ sub_putq_cb(void *arg)
// to replace this with a patricia trie, like old nanomsg had.
static int
-sub_subscribe(sub_sock *s, const void *buf, size_t sz)
+sub_subscribe(void *arg, const void *buf, size_t sz)
{
+ sub_sock * s = arg;
sub_topic *topic;
sub_topic *newtopic;
@@ -222,8 +226,9 @@ sub_subscribe(sub_sock *s, const void *buf, size_t sz)
}
static int
-sub_unsubscribe(sub_sock *s, const void *buf, size_t sz)
+sub_unsubscribe(void *arg, const void *buf, size_t sz)
{
+ sub_sock * s = arg;
sub_topic *topic;
int rv;
@@ -252,31 +257,17 @@ sub_unsubscribe(sub_sock *s, const void *buf, size_t sz)
}
static int
-sub_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
+sub_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
- sub_sock *s = arg;
- int rv = NNG_ENOTSUP;
-
- if (opt == nng_optid_raw) {
- rv = nni_setopt_int(&s->raw, buf, sz, 0, 1);
- } else if (opt == nng_optid_sub_subscribe) {
- rv = sub_subscribe(s, buf, sz);
- } else if (opt == nng_optid_sub_unsubscribe) {
- rv = sub_unsubscribe(s, buf, sz);
- }
- return (rv);
+ sub_sock *s = arg;
+ return (nni_setopt_int(&s->raw, buf, sz, 0, 1));
}
static int
-sub_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
+sub_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
- sub_sock *s = arg;
- int rv = NNG_ENOTSUP;
-
- if (opt == nng_optid_raw) {
- rv = nni_getopt_int(s->raw, buf, szp);
- }
- return (rv);
+ sub_sock *s = arg;
+ return (nni_getopt_int(s->raw, buf, szp));
}
static nni_msg *
@@ -330,13 +321,32 @@ static nni_proto_pipe_ops sub_pipe_ops = {
.pipe_stop = sub_pipe_stop,
};
+static nni_proto_sock_option sub_sock_options[] = {
+ {
+ .pso_name = NNG_OPT_RAW,
+ .pso_getopt = sub_sock_getopt_raw,
+ .pso_setopt = sub_sock_setopt_raw,
+ },
+ {
+ .pso_name = NNG_OPT_SUB_SUBSCRIBE,
+ .pso_getopt = NULL,
+ .pso_setopt = sub_subscribe,
+ },
+ {
+ .pso_name = NNG_OPT_SUB_UNSUBSCRIBE,
+ .pso_getopt = NULL,
+ .pso_setopt = sub_unsubscribe,
+ },
+ // terminate list
+ { NULL, NULL, NULL },
+};
+
static nni_proto_sock_ops sub_sock_ops = {
.sock_init = sub_sock_init,
.sock_fini = sub_sock_fini,
.sock_open = sub_sock_open,
.sock_close = sub_sock_close,
- .sock_setopt = sub_sock_setopt,
- .sock_getopt = sub_sock_getopt,
+ .sock_options = sub_sock_options,
.sock_rfilter = sub_sock_rfilter,
};
diff --git a/src/protocol/reqrep/rep.c b/src/protocol/reqrep/rep.c
index 6641c58f..cd9411d9 100644
--- a/src/protocol/reqrep/rep.c
+++ b/src/protocol/reqrep/rep.c
@@ -343,32 +343,36 @@ rep_pipe_putq_cb(void *arg)
}
static int
-rep_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
+rep_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
- rep_sock *s = arg;
- int rv = NNG_ENOTSUP;
-
- if (opt == nng_optid_maxttl) {
- rv = nni_setopt_int(&s->ttl, buf, sz, 1, 255);
- } else if (opt == nng_optid_raw) {
- rv = nni_setopt_int(&s->raw, buf, sz, 0, 1);
+ rep_sock *s = arg;
+ int rv;
+ rv = nni_setopt_int(&s->raw, buf, sz, 0, 1);
+ if (rv == 0) {
nni_sock_senderr(s->sock, s->raw ? 0 : NNG_ESTATE);
}
return (rv);
}
static int
-rep_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
+rep_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
- rep_sock *s = arg;
- int rv = NNG_ENOTSUP;
+ rep_sock *s = arg;
+ return (nni_getopt_int(s->raw, buf, szp));
+}
- if (opt == nng_optid_maxttl) {
- rv = nni_getopt_int(s->ttl, buf, szp);
- } else if (opt == nng_optid_raw) {
- rv = nni_getopt_int(s->raw, buf, szp);
- }
- return (rv);
+static int
+rep_sock_setopt_maxttl(void *arg, const void *buf, size_t sz)
+{
+ rep_sock *s = arg;
+ return (nni_setopt_int(&s->ttl, buf, sz, 1, 255));
+}
+
+static int
+rep_sock_getopt_maxttl(void *arg, void *buf, size_t *szp)
+{
+ rep_sock *s = arg;
+ return (nni_getopt_int(s->ttl, buf, szp));
}
static nni_msg *
@@ -445,13 +449,27 @@ static nni_proto_pipe_ops rep_pipe_ops = {
.pipe_stop = rep_pipe_stop,
};
+static nni_proto_sock_option rep_sock_options[] = {
+ {
+ .pso_name = NNG_OPT_RAW,
+ .pso_getopt = rep_sock_getopt_raw,
+ .pso_setopt = rep_sock_setopt_raw,
+ },
+ {
+ .pso_name = NNG_OPT_MAXTTL,
+ .pso_getopt = rep_sock_getopt_maxttl,
+ .pso_setopt = rep_sock_setopt_maxttl,
+ },
+ // terminate list
+ { NULL, NULL, NULL },
+};
+
static nni_proto_sock_ops rep_sock_ops = {
.sock_init = rep_sock_init,
.sock_fini = rep_sock_fini,
.sock_open = rep_sock_open,
.sock_close = rep_sock_close,
- .sock_setopt = rep_sock_setopt,
- .sock_getopt = rep_sock_getopt,
+ .sock_options = rep_sock_options,
.sock_rfilter = rep_sock_rfilter,
.sock_sfilter = rep_sock_sfilter,
};
diff --git a/src/protocol/reqrep/req.c b/src/protocol/reqrep/req.c
index c2008a9a..7d47b0b3 100644
--- a/src/protocol/reqrep/req.c
+++ b/src/protocol/reqrep/req.c
@@ -15,8 +15,9 @@
#include "core/nng_impl.h"
// Request protocol. The REQ protocol is the "request" side of a
-// request-reply pair. This is useful for building RPC clients, for
-// example.
+// request-reply pair. This is useful for building RPC clients, for example.
+
+const char *nng_opt_req_resendtime = NNG_OPT_REQ_RESENDTIME;
typedef struct req_pipe req_pipe;
typedef struct req_sock req_sock;
@@ -245,44 +246,50 @@ req_pipe_stop(void *arg)
}
static int
-req_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
+req_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
- req_sock *s = arg;
- int rv = NNG_ENOTSUP;
-
- if (opt == nng_optid_req_resendtime) {
- rv = nni_setopt_usec(&s->retry, buf, sz);
-
- } else if (opt == nng_optid_raw) {
- rv = nni_setopt_int(&s->raw, buf, sz, 0, 1);
- if (rv == 0) {
- nni_sock_recverr(s->sock, s->raw ? 0 : NNG_ESTATE);
- }
-
- } else if (opt == nng_optid_maxttl) {
- rv = nni_setopt_int(&s->ttl, buf, sz, 1, 255);
+ req_sock *s = arg;
+ int rv;
+ rv = nni_setopt_int(&s->raw, buf, sz, 0, 1);
+ if (rv == 0) {
+ nni_sock_recverr(s->sock, s->raw ? 0 : NNG_ESTATE);
}
-
return (rv);
}
static int
-req_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
+req_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
- req_sock *s = arg;
- int rv = NNG_ENOTSUP;
+ req_sock *s = arg;
+ return (nni_getopt_int(s->raw, buf, szp));
+}
- if (opt == nng_optid_req_resendtime) {
- rv = nni_getopt_usec(s->retry, buf, szp);
+static int
+req_sock_setopt_maxttl(void *arg, const void *buf, size_t sz)
+{
+ req_sock *s = arg;
+ return (nni_setopt_int(&s->ttl, buf, sz, 1, 255));
+}
- } else if (opt == nng_optid_raw) {
- rv = nni_getopt_int(s->raw, buf, szp);
+static int
+req_sock_getopt_maxttl(void *arg, void *buf, size_t *szp)
+{
+ req_sock *s = arg;
+ return (nni_getopt_int(s->ttl, buf, szp));
+}
- } else if (opt == nng_optid_maxttl) {
- rv = nni_getopt_int(s->ttl, buf, szp);
- }
+static int
+req_sock_setopt_resendtime(void *arg, const void *buf, size_t sz)
+{
+ req_sock *s = arg;
+ return (nni_setopt_usec(&s->retry, buf, sz));
+}
- return (rv);
+static int
+req_sock_getopt_resendtime(void *arg, void *buf, size_t *szp)
+{
+ req_sock *s = arg;
+ return (nni_getopt_usec(s->retry, buf, szp));
}
// Raw and cooked mode differ in the way they send messages out.
@@ -597,13 +604,32 @@ static nni_proto_pipe_ops req_pipe_ops = {
.pipe_stop = req_pipe_stop,
};
+static nni_proto_sock_option req_sock_options[] = {
+ {
+ .pso_name = NNG_OPT_RAW,
+ .pso_getopt = req_sock_getopt_raw,
+ .pso_setopt = req_sock_setopt_raw,
+ },
+ {
+ .pso_name = NNG_OPT_MAXTTL,
+ .pso_getopt = req_sock_getopt_maxttl,
+ .pso_setopt = req_sock_setopt_maxttl,
+ },
+ {
+ .pso_name = NNG_OPT_REQ_RESENDTIME,
+ .pso_getopt = req_sock_getopt_resendtime,
+ .pso_setopt = req_sock_setopt_resendtime,
+ },
+ // terminate list
+ { NULL, NULL, NULL },
+};
+
static nni_proto_sock_ops req_sock_ops = {
.sock_init = req_sock_init,
.sock_fini = req_sock_fini,
.sock_open = req_sock_open,
.sock_close = req_sock_close,
- .sock_setopt = req_sock_setopt,
- .sock_getopt = req_sock_getopt,
+ .sock_options = req_sock_options,
.sock_rfilter = req_sock_rfilter,
.sock_sfilter = req_sock_sfilter,
};
diff --git a/src/protocol/survey/respond.c b/src/protocol/survey/respond.c
index 89e19e91..70dbd704 100644
--- a/src/protocol/survey/respond.c
+++ b/src/protocol/survey/respond.c
@@ -343,42 +343,36 @@ resp_putq_cb(void *arg)
}
static int
-resp_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
+resp_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
- resp_sock *s = arg;
- int rv = NNG_ENOTSUP;
- int oldraw;
-
- if (opt == nng_optid_maxttl) {
- rv = nni_setopt_int(&s->ttl, buf, sz, 1, 255);
-
- } else if (opt == nng_optid_raw) {
- oldraw = s->raw;
- rv = nni_setopt_int(&s->raw, buf, sz, 0, 1);
- if (oldraw != s->raw) {
- if (!s->raw) {
- nni_sock_senderr(s->nsock, 0);
- } else {
- nni_sock_senderr(s->nsock, NNG_ESTATE);
- }
- }
- }
+ resp_sock *s = arg;
+ int rv;
+ if ((rv = nni_setopt_int(&s->raw, buf, sz, 0, 1)) == 0) {
+ nni_sock_senderr(s->nsock, s->raw ? 0 : NNG_ESTATE);
+ }
return (rv);
}
static int
-resp_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
+resp_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
- resp_sock *s = arg;
- int rv = NNG_ENOTSUP;
+ resp_sock *s = arg;
+ return (nni_getopt_int(s->raw, buf, szp));
+}
- if (opt == nng_optid_maxttl) {
- rv = nni_getopt_int(s->ttl, buf, szp);
- } else if (opt == nng_optid_raw) {
- rv = nni_getopt_int(s->raw, buf, szp);
- }
- return (rv);
+static int
+resp_sock_setopt_maxttl(void *arg, const void *buf, size_t sz)
+{
+ resp_sock *s = arg;
+ return (nni_setopt_int(&s->ttl, buf, sz, 1, 255));
+}
+
+static int
+resp_sock_getopt_maxttl(void *arg, void *buf, size_t *szp)
+{
+ resp_sock *s = arg;
+ return (nni_getopt_int(s->ttl, buf, szp));
}
static nni_msg *
@@ -453,13 +447,27 @@ static nni_proto_pipe_ops resp_pipe_ops = {
.pipe_stop = resp_pipe_stop,
};
+static nni_proto_sock_option resp_sock_options[] = {
+ {
+ .pso_name = NNG_OPT_RAW,
+ .pso_getopt = resp_sock_getopt_raw,
+ .pso_setopt = resp_sock_setopt_raw,
+ },
+ {
+ .pso_name = NNG_OPT_MAXTTL,
+ .pso_getopt = resp_sock_getopt_maxttl,
+ .pso_setopt = resp_sock_setopt_maxttl,
+ },
+ // terminate list
+ { NULL, NULL, NULL },
+};
+
static nni_proto_sock_ops resp_sock_ops = {
.sock_init = resp_sock_init,
.sock_fini = resp_sock_fini,
.sock_open = resp_sock_open,
.sock_close = resp_sock_close,
- .sock_setopt = resp_sock_setopt,
- .sock_getopt = resp_sock_getopt,
+ .sock_options = resp_sock_options,
.sock_rfilter = resp_sock_rfilter,
.sock_sfilter = resp_sock_sfilter,
};
diff --git a/src/protocol/survey/survey.c b/src/protocol/survey/survey.c
index e90c7f57..361b9d37 100644
--- a/src/protocol/survey/survey.c
+++ b/src/protocol/survey/survey.c
@@ -267,44 +267,38 @@ failed:
}
static int
-surv_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
+surv_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
- surv_sock *s = arg;
- int rv = NNG_ENOTSUP;
- int oldraw;
-
- if (opt == nng_optid_surveyor_surveytime) {
- rv = nni_setopt_usec(&s->survtime, buf, sz);
-
- } else if (opt == nng_optid_raw) {
- oldraw = s->raw;
- rv = nni_setopt_int(&s->raw, buf, sz, 0, 1);
- if (oldraw != s->raw) {
- if (s->raw) {
- nni_sock_recverr(s->nsock, 0);
- } else {
- nni_sock_recverr(s->nsock, NNG_ESTATE);
- }
- s->survid = 0;
- nni_timer_cancel(&s->timer);
- }
- }
+ surv_sock *s = arg;
+ int rv;
+ if ((rv = nni_setopt_int(&s->raw, buf, sz, 0, 1)) == 0) {
+ nni_sock_recverr(s->nsock, s->raw ? 0 : NNG_ESTATE);
+ s->survid = 0;
+ nni_timer_cancel(&s->timer);
+ }
return (rv);
}
static int
-surv_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
+surv_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
- surv_sock *s = arg;
- int rv = NNG_ENOTSUP;
+ surv_sock *s = arg;
+ return (nni_getopt_int(s->raw, buf, szp));
+}
- if (opt == nng_optid_surveyor_surveytime) {
- rv = nni_getopt_usec(s->survtime, buf, szp);
- } else if (opt == nng_optid_raw) {
- rv = nni_getopt_int(s->raw, buf, szp);
- }
- return (rv);
+static int
+surv_sock_setopt_surveytime(void *arg, const void *buf, size_t sz)
+{
+ surv_sock *s = arg;
+ return (nni_setopt_usec(&s->survtime, buf, sz));
+}
+
+static int
+surv_sock_getopt_surveytime(void *arg, void *buf, size_t *szp)
+{
+ surv_sock *s = arg;
+ return (nni_getopt_usec(s->survtime, buf, szp));
}
static void
@@ -418,13 +412,27 @@ static nni_proto_pipe_ops surv_pipe_ops = {
.pipe_stop = surv_pipe_stop,
};
+static nni_proto_sock_option surv_sock_options[] = {
+ {
+ .pso_name = NNG_OPT_RAW,
+ .pso_getopt = surv_sock_getopt_raw,
+ .pso_setopt = surv_sock_setopt_raw,
+ },
+ {
+ .pso_name = NNG_OPT_SURVEYOR_SURVEYTIME,
+ .pso_getopt = surv_sock_getopt_surveytime,
+ .pso_setopt = surv_sock_setopt_surveytime,
+ },
+ // terminate list
+ { NULL, NULL, NULL },
+};
+
static nni_proto_sock_ops surv_sock_ops = {
.sock_init = surv_sock_init,
.sock_fini = surv_sock_fini,
.sock_open = surv_sock_open,
.sock_close = surv_sock_close,
- .sock_setopt = surv_sock_setopt,
- .sock_getopt = surv_sock_getopt,
+ .sock_options = surv_sock_options,
.sock_rfilter = surv_sock_rfilter,
.sock_sfilter = surv_sock_sfilter,
};