aboutsummaryrefslogtreecommitdiff
path: root/src/core/protocol.c
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/core/protocol.c
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/core/protocol.c')
-rw-r--r--src/core/protocol.c83
1 files changed, 8 insertions, 75 deletions
diff --git a/src/core/protocol.c b/src/core/protocol.c
index a60454de..7faf9068 100644
--- a/src/core/protocol.c
+++ b/src/core/protocol.c
@@ -1,5 +1,6 @@
//
// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// Copyright 2017 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -13,82 +14,14 @@
// Protocol related stuff - generically.
-// The list of protocols is hardwired. This is reasonably unlikely to
-// change, as adding new protocols is not something intended to be done
-// outside of the core.
-extern nni_proto nni_bus_proto;
-extern nni_proto nni_pair_proto;
-extern nni_proto nni_rep_proto;
-extern nni_proto nni_req_proto;
-extern nni_proto nni_pub_proto;
-extern nni_proto nni_sub_proto;
-extern nni_proto nni_push_proto;
-extern nni_proto nni_pull_proto;
-extern nni_proto nni_surveyor_proto;
-extern nni_proto nni_respondent_proto;
-
-static nni_proto *protocols[] = {
- // clang-format off
- &nni_bus_proto,
- &nni_pair_proto,
- &nni_rep_proto,
- &nni_req_proto,
- &nni_pub_proto,
- &nni_sub_proto,
- &nni_push_proto,
- &nni_pull_proto,
- &nni_surveyor_proto,
- &nni_respondent_proto,
- NULL
- // clang-format on
-};
-
-nni_proto *
-nni_proto_find(uint16_t num)
-{
- int i;
- nni_proto *p;
-
- for (i = 0; (p = protocols[i]) != NULL; i++) {
- if (p->proto_self == num) {
- break;
- }
- }
- return (p);
-}
-
-const char *
-nni_proto_name(uint16_t num)
-{
- nni_proto *p;
-
- if ((p = nni_proto_find(num)) == NULL) {
- return (NULL);
- }
- return (p->proto_name);
-}
-
-uint16_t
-nni_proto_number(const char *name)
-{
- nni_proto *p;
- int i;
-
- for (i = 0; (p = protocols[i]) != NULL; i++) {
- if (strcmp(p->proto_name, name) == 0) {
- return (p->proto_self);
- }
- }
- return (NNG_PROTO_NONE);
-}
-
-uint16_t
-nni_proto_peer(uint16_t num)
+int
+nni_proto_open(nng_socket *sockidp, const nni_proto *proto)
{
- nni_proto *p;
+ int rv;
+ nni_sock *sock;
- if ((p = nni_proto_find(num)) == NULL) {
- return (NNG_PROTO_NONE);
+ if ((rv = nni_sock_open(&sock, proto)) == 0) {
+ *sockidp = nni_sock_id(sock); // Keep socket held open.
}
- return (p->proto_peer);
+ return (rv);
}