aboutsummaryrefslogtreecommitdiff
path: root/src/protocol
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-08 21:19:09 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-09 02:38:55 -0700
commitd64f12553eb6ceb67ed6f6a5b2ceb6c061d375ba (patch)
treef6bdac79578176f0d00528d191f862009e761eac /src/protocol
parent5f0398de8edd1ed4ddbf6455c66273a6608aad9a (diff)
downloadnng-d64f12553eb6ceb67ed6f6a5b2ceb6c061d375ba.tar.gz
nng-d64f12553eb6ceb67ed6f6a5b2ceb6c061d375ba.tar.bz2
nng-d64f12553eb6ceb67ed6f6a5b2ceb6c061d375ba.zip
fixes #44 open protocol by "name" (symbol) instead number
fixes #38 Make protocols "pluggable", or at least optional This is a breaking change, as we've done away with the central registered list of protocols, and instead demand the user call nng_xxx_open() where xxx is a protocol name. (We did keep a table around in the compat framework though.) There is a nice way for protocols to plug in via an nni_proto_open(), where they can use a generic constructor that they use to build a protocol specific constructor (passing their ops vector in.)
Diffstat (limited to 'src/protocol')
-rw-r--r--src/protocol/bus/bus.c21
-rw-r--r--src/protocol/pair/pair.c29
-rw-r--r--src/protocol/pipeline/pull.c32
-rw-r--r--src/protocol/pipeline/push.c32
-rw-r--r--src/protocol/pubsub/pub.c21
-rw-r--r--src/protocol/pubsub/sub.c26
-rw-r--r--src/protocol/reqrep/rep.c12
-rw-r--r--src/protocol/reqrep/req.c19
-rw-r--r--src/protocol/survey/respond.c12
-rw-r--r--src/protocol/survey/survey.c14
10 files changed, 173 insertions, 45 deletions
diff --git a/src/protocol/bus/bus.c b/src/protocol/bus/bus.c
index 3070b90d..c5a6ce06 100644
--- a/src/protocol/bus/bus.c
+++ b/src/protocol/bus/bus.c
@@ -104,6 +104,14 @@ nni_bus_sock_open(void *arg)
}
static void
+nni_bus_sock_close(void *arg)
+{
+ nni_bus_sock *psock = arg;
+
+ nni_aio_cancel(&psock->aio_getq, NNG_ECLOSED);
+}
+
+static void
nni_bus_pipe_fini(void *arg)
{
nni_bus_pipe *ppipe = arg;
@@ -383,6 +391,7 @@ static nni_proto_sock_ops nni_bus_sock_ops = {
.sock_init = nni_bus_sock_init,
.sock_fini = nni_bus_sock_fini,
.sock_open = nni_bus_sock_open,
+ .sock_close = nni_bus_sock_close,
.sock_setopt = nni_bus_sock_setopt,
.sock_getopt = nni_bus_sock_getopt,
};
@@ -390,10 +399,16 @@ static nni_proto_sock_ops nni_bus_sock_ops = {
// This is the global protocol structure -- our linkage to the core.
// This should be the only global non-static symbol in this file.
nni_proto nni_bus_proto = {
- .proto_self = NNG_PROTO_BUS,
- .proto_peer = NNG_PROTO_BUS,
- .proto_name = "bus",
+ .proto_version = NNI_PROTOCOL_VERSION,
+ .proto_self = { NNG_PROTO_BUS_V0, "bus" },
+ .proto_peer = { NNG_PROTO_BUS_V0, "bus" },
.proto_flags = NNI_PROTO_FLAG_SNDRCV,
.proto_sock_ops = &nni_bus_sock_ops,
.proto_pipe_ops = &nni_bus_pipe_ops,
};
+
+int
+nng_bus0_open(nng_socket *sidp)
+{
+ return (nni_proto_open(sidp, &nni_bus_proto));
+}
diff --git a/src/protocol/pair/pair.c b/src/protocol/pair/pair.c
index 55ce5aa9..59465293 100644
--- a/src/protocol/pair/pair.c
+++ b/src/protocol/pair/pair.c
@@ -231,6 +231,18 @@ nni_pair_send_cb(void *arg)
nni_msgq_aio_get(psock->uwq, &ppipe->aio_getq);
}
+static void
+nni_pair_sock_open(void *arg)
+{
+ NNI_ARG_UNUSED(arg);
+}
+
+static void
+nni_pair_sock_close(void *arg)
+{
+ NNI_ARG_UNUSED(arg);
+}
+
static int
nni_pair_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
{
@@ -263,9 +275,6 @@ nni_pair_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
return (rv);
}
-// This is the global protocol structure -- our linkage to the core.
-// This should be the only global non-static symbol in this file.
-
static nni_proto_pipe_ops nni_pair_pipe_ops = {
.pipe_init = nni_pair_pipe_init,
.pipe_fini = nni_pair_pipe_fini,
@@ -276,15 +285,23 @@ static nni_proto_pipe_ops nni_pair_pipe_ops = {
static nni_proto_sock_ops nni_pair_sock_ops = {
.sock_init = nni_pair_sock_init,
.sock_fini = nni_pair_sock_fini,
+ .sock_open = nni_pair_sock_open,
+ .sock_close = nni_pair_sock_close,
.sock_setopt = nni_pair_sock_setopt,
.sock_getopt = nni_pair_sock_getopt,
};
nni_proto nni_pair_proto = {
- .proto_self = NNG_PROTO_PAIR,
- .proto_peer = NNG_PROTO_PAIR,
- .proto_name = "pair",
+ .proto_version = NNI_PROTOCOL_VERSION,
+ .proto_self = { NNG_PROTO_PAIR_V0, "pair" },
+ .proto_peer = { NNG_PROTO_PAIR_V0, "pair" },
.proto_flags = NNI_PROTO_FLAG_SNDRCV,
.proto_sock_ops = &nni_pair_sock_ops,
.proto_pipe_ops = &nni_pair_pipe_ops,
};
+
+int
+nng_pair0_open(nng_socket *sidp)
+{
+ return (nni_proto_open(sidp, &nni_pair_proto));
+}
diff --git a/src/protocol/pipeline/pull.c b/src/protocol/pipeline/pull.c
index cde79824..e3c73342 100644
--- a/src/protocol/pipeline/pull.c
+++ b/src/protocol/pipeline/pull.c
@@ -56,9 +56,7 @@ nni_pull_sock_fini(void *arg)
{
nni_pull_sock *pull = arg;
- if (pull != NULL) {
- NNI_FREE_STRUCT(pull);
- }
+ NNI_FREE_STRUCT(pull);
}
static int
@@ -163,6 +161,18 @@ nni_pull_putq(nni_pull_pipe *pp, nni_msg *msg)
nni_msgq_aio_put(pull->urq, &pp->putq_aio);
}
+static void
+nni_pull_sock_open(void *arg)
+{
+ NNI_ARG_UNUSED(arg);
+}
+
+static void
+nni_pull_sock_close(void *arg)
+{
+ NNI_ARG_UNUSED(arg);
+}
+
static int
nni_pull_sock_setopt(void *arg, int opt, const void *buf, size_t sz)
{
@@ -195,8 +205,6 @@ nni_pull_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
return (rv);
}
-// This is the global protocol structure -- our linkage to the core.
-// This should be the only global non-static symbol in this file.
static nni_proto_pipe_ops nni_pull_pipe_ops = {
.pipe_init = nni_pull_pipe_init,
.pipe_fini = nni_pull_pipe_fini,
@@ -207,15 +215,23 @@ static nni_proto_pipe_ops nni_pull_pipe_ops = {
static nni_proto_sock_ops nni_pull_sock_ops = {
.sock_init = nni_pull_sock_init,
.sock_fini = nni_pull_sock_fini,
+ .sock_open = nni_pull_sock_open,
+ .sock_close = nni_pull_sock_close,
.sock_setopt = nni_pull_sock_setopt,
.sock_getopt = nni_pull_sock_getopt,
};
nni_proto nni_pull_proto = {
- .proto_self = NNG_PROTO_PULL,
- .proto_peer = NNG_PROTO_PUSH,
- .proto_name = "pull",
+ .proto_version = NNI_PROTOCOL_VERSION,
+ .proto_self = { NNG_PROTO_PULL_V0, "pull" },
+ .proto_peer = { NNG_PROTO_PUSH_V0, "push" },
.proto_flags = NNI_PROTO_FLAG_RCV,
.proto_pipe_ops = &nni_pull_pipe_ops,
.proto_sock_ops = &nni_pull_sock_ops,
};
+
+int
+nng_pull0_open(nng_socket *sidp)
+{
+ return (nni_proto_open(sidp, &nni_pull_proto));
+}
diff --git a/src/protocol/pipeline/push.c b/src/protocol/pipeline/push.c
index b7d4322c..14b3b191 100644
--- a/src/protocol/pipeline/push.c
+++ b/src/protocol/pipeline/push.c
@@ -63,9 +63,19 @@ nni_push_sock_fini(void *arg)
{
nni_push_sock *push = arg;
- if (push != NULL) {
- NNI_FREE_STRUCT(push);
- }
+ NNI_FREE_STRUCT(push);
+}
+
+static void
+nni_push_sock_open(void *arg)
+{
+ NNI_ARG_UNUSED(arg);
+}
+
+static void
+nni_push_sock_close(void *arg)
+{
+ NNI_ARG_UNUSED(arg);
}
static void
@@ -221,8 +231,6 @@ nni_push_sock_getopt(void *arg, int opt, void *buf, size_t *szp)
return (rv);
}
-// This is the global protocol structure -- our linkage to the core.
-// This should be the only global non-static symbol in this file.
static nni_proto_pipe_ops nni_push_pipe_ops = {
.pipe_init = nni_push_pipe_init,
.pipe_fini = nni_push_pipe_fini,
@@ -233,15 +241,23 @@ static nni_proto_pipe_ops nni_push_pipe_ops = {
static nni_proto_sock_ops nni_push_sock_ops = {
.sock_init = nni_push_sock_init,
.sock_fini = nni_push_sock_fini,
+ .sock_open = nni_push_sock_open,
+ .sock_close = nni_push_sock_close,
.sock_setopt = nni_push_sock_setopt,
.sock_getopt = nni_push_sock_getopt,
};
nni_proto nni_push_proto = {
- .proto_self = NNG_PROTO_PUSH,
- .proto_peer = NNG_PROTO_PULL,
- .proto_name = "push",
+ .proto_version = NNI_PROTOCOL_VERSION,
+ .proto_self = { NNG_PROTO_PUSH_V0, "push" },
+ .proto_peer = { NNG_PROTO_PULL_V0, "pull" },
.proto_flags = NNI_PROTO_FLAG_SND,
.proto_pipe_ops = &nni_push_pipe_ops,
.proto_sock_ops = &nni_push_sock_ops,
};
+
+int
+nng_push0_open(nng_socket *sidp)
+{
+ return (nni_proto_open(sidp, &nni_push_proto));
+}
diff --git a/src/protocol/pubsub/pub.c b/src/protocol/pubsub/pub.c
index e32f179a..161a5d79 100644
--- a/src/protocol/pubsub/pub.c
+++ b/src/protocol/pubsub/pub.c
@@ -98,6 +98,14 @@ nni_pub_sock_open(void *arg)
}
static void
+nni_pub_sock_close(void *arg)
+{
+ nni_pub_sock *pub = arg;
+
+ nni_aio_cancel(&pub->aio_getq, NNG_ECLOSED);
+}
+
+static void
nni_pub_pipe_fini(void *arg)
{
nni_pub_pipe *pp = arg;
@@ -319,15 +327,22 @@ nni_proto_sock_ops nni_pub_sock_ops = {
.sock_init = nni_pub_sock_init,
.sock_fini = nni_pub_sock_fini,
.sock_open = nni_pub_sock_open,
+ .sock_close = nni_pub_sock_close,
.sock_setopt = nni_pub_sock_setopt,
.sock_getopt = nni_pub_sock_getopt,
};
nni_proto nni_pub_proto = {
- .proto_self = NNG_PROTO_PUB,
- .proto_peer = NNG_PROTO_SUB,
- .proto_name = "pub",
+ .proto_version = NNI_PROTOCOL_VERSION,
+ .proto_self = { NNG_PROTO_PUB_V0, "pub" },
+ .proto_peer = { NNG_PROTO_SUB_V0, "sub" },
.proto_flags = NNI_PROTO_FLAG_SND,
.proto_sock_ops = &nni_pub_sock_ops,
.proto_pipe_ops = &nni_pub_pipe_ops,
};
+
+int
+nng_pub0_open(nng_socket *sidp)
+{
+ return (nni_proto_open(sidp, &nni_pub_proto));
+}
diff --git a/src/protocol/pubsub/sub.c b/src/protocol/pubsub/sub.c
index 03d76e2d..53f01e0f 100644
--- a/src/protocol/pubsub/sub.c
+++ b/src/protocol/pubsub/sub.c
@@ -79,6 +79,18 @@ nni_sub_sock_fini(void *arg)
NNI_FREE_STRUCT(sub);
}
+static void
+nni_sub_sock_open(void *arg)
+{
+ NNI_ARG_UNUSED(arg);
+}
+
+static void
+nni_sub_sock_close(void *arg)
+{
+ NNI_ARG_UNUSED(arg);
+}
+
static int
nni_sub_pipe_init(void **spp, nni_pipe *pipe, void *ssock)
{
@@ -330,16 +342,24 @@ static nni_proto_pipe_ops nni_sub_pipe_ops = {
static nni_proto_sock_ops nni_sub_sock_ops = {
.sock_init = nni_sub_sock_init,
.sock_fini = nni_sub_sock_fini,
+ .sock_open = nni_sub_sock_open,
+ .sock_close = nni_sub_sock_close,
.sock_setopt = nni_sub_sock_setopt,
.sock_getopt = nni_sub_sock_getopt,
.sock_rfilter = nni_sub_sock_rfilter,
};
nni_proto nni_sub_proto = {
- .proto_self = NNG_PROTO_SUB,
- .proto_peer = NNG_PROTO_PUB,
- .proto_name = "sub",
+ .proto_version = NNI_PROTOCOL_VERSION,
+ .proto_self = { NNG_PROTO_SUB_V0, "sub" },
+ .proto_peer = { NNG_PROTO_PUB_V0, "pub" },
.proto_flags = NNI_PROTO_FLAG_RCV,
.proto_sock_ops = &nni_sub_sock_ops,
.proto_pipe_ops = &nni_sub_pipe_ops,
};
+
+int
+nng_sub0_open(nng_socket *sidp)
+{
+ return (nni_proto_open(sidp, &nni_sub_proto));
+}
diff --git a/src/protocol/reqrep/rep.c b/src/protocol/reqrep/rep.c
index c7546182..1adfd0f8 100644
--- a/src/protocol/reqrep/rep.c
+++ b/src/protocol/reqrep/rep.c
@@ -488,10 +488,16 @@ static nni_proto_sock_ops nni_rep_sock_ops = {
};
nni_proto nni_rep_proto = {
- .proto_self = NNG_PROTO_REP,
- .proto_peer = NNG_PROTO_REQ,
- .proto_name = "rep",
+ .proto_version = NNI_PROTOCOL_VERSION,
+ .proto_self = { NNG_PROTO_REP_V0, "rep" },
+ .proto_peer = { NNG_PROTO_REQ_V0, "req" },
.proto_flags = NNI_PROTO_FLAG_SNDRCV,
.proto_sock_ops = &nni_rep_sock_ops,
.proto_pipe_ops = &nni_rep_pipe_ops,
};
+
+int
+nng_rep0_open(nng_socket *sidp)
+{
+ return (nni_proto_open(sidp, &nni_rep_proto));
+}
diff --git a/src/protocol/reqrep/req.c b/src/protocol/reqrep/req.c
index 7ec53c90..d0dd3887 100644
--- a/src/protocol/reqrep/req.c
+++ b/src/protocol/reqrep/req.c
@@ -112,6 +112,12 @@ nni_req_sock_init(void **reqp, nni_sock *sock)
}
static void
+nni_req_sock_open(void *arg)
+{
+ NNI_ARG_UNUSED(arg);
+}
+
+static void
nni_req_sock_close(void *arg)
{
nni_req_sock *req = arg;
@@ -626,6 +632,7 @@ static nni_proto_pipe_ops nni_req_pipe_ops = {
static nni_proto_sock_ops nni_req_sock_ops = {
.sock_init = nni_req_sock_init,
.sock_fini = nni_req_sock_fini,
+ .sock_open = nni_req_sock_open,
.sock_close = nni_req_sock_close,
.sock_setopt = nni_req_sock_setopt,
.sock_getopt = nni_req_sock_getopt,
@@ -634,10 +641,16 @@ static nni_proto_sock_ops nni_req_sock_ops = {
};
nni_proto nni_req_proto = {
- .proto_self = NNG_PROTO_REQ,
- .proto_peer = NNG_PROTO_REP,
- .proto_name = "req",
+ .proto_version = NNI_PROTOCOL_VERSION,
+ .proto_self = { NNG_PROTO_REQ_V0, "req" },
+ .proto_peer = { NNG_PROTO_REP_V0, "rep" },
.proto_flags = NNI_PROTO_FLAG_SNDRCV,
.proto_sock_ops = &nni_req_sock_ops,
.proto_pipe_ops = &nni_req_pipe_ops,
};
+
+int
+nng_req0_open(nng_socket *sidp)
+{
+ return (nni_proto_open(sidp, &nni_req_proto));
+}
diff --git a/src/protocol/survey/respond.c b/src/protocol/survey/respond.c
index 089e730e..4db79b86 100644
--- a/src/protocol/survey/respond.c
+++ b/src/protocol/survey/respond.c
@@ -504,10 +504,16 @@ static nni_proto_sock_ops nni_resp_sock_ops = {
};
nni_proto nni_respondent_proto = {
- .proto_self = NNG_PROTO_RESPONDENT,
- .proto_peer = NNG_PROTO_SURVEYOR,
- .proto_name = "respondent",
+ .proto_version = NNI_PROTOCOL_VERSION,
+ .proto_self = { NNG_PROTO_RESPONDENT_V0, "respondent" },
+ .proto_peer = { NNG_PROTO_SURVEYOR_V0, "surveyor" },
.proto_flags = NNI_PROTO_FLAG_SNDRCV,
.proto_sock_ops = &nni_resp_sock_ops,
.proto_pipe_ops = &nni_resp_pipe_ops,
};
+
+int
+nng_respondent0_open(nng_socket *sidp)
+{
+ return (nni_proto_open(sidp, &nni_respondent_proto));
+}
diff --git a/src/protocol/survey/survey.c b/src/protocol/survey/survey.c
index 633e1491..91fe4ad3 100644
--- a/src/protocol/survey/survey.c
+++ b/src/protocol/survey/survey.c
@@ -470,13 +470,17 @@ static nni_proto_sock_ops nni_surv_sock_ops = {
.sock_sfilter = nni_surv_sock_sfilter,
};
-// This is the global protocol structure -- our linkage to the core.
-// This should be the only global non-static symbol in this file.
nni_proto nni_surveyor_proto = {
- .proto_self = NNG_PROTO_SURVEYOR,
- .proto_peer = NNG_PROTO_RESPONDENT,
- .proto_name = "surveyor",
+ .proto_version = NNI_PROTOCOL_VERSION,
+ .proto_self = { NNG_PROTO_SURVEYOR_V0, "surveyor" },
+ .proto_peer = { NNG_PROTO_RESPONDENT_V0, "respondent" },
.proto_flags = NNI_PROTO_FLAG_SNDRCV,
.proto_sock_ops = &nni_surv_sock_ops,
.proto_pipe_ops = &nni_surv_pipe_ops,
};
+
+int
+nng_surveyor0_open(nng_socket *sidp)
+{
+ return (nni_proto_open(sidp, &nni_surveyor_proto));
+}