aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-10-31 13:06:38 -0700
committerGarrett D'Amore <garrett@damore.org>2017-11-02 16:10:26 -0700
commit7bf591e20a94b8d926f92ab9b320f3b75d342345 (patch)
treed67ce7cab328a004346419047feede7d579dad77 /src/core
parentd340af7dc250388f48d36c5078c4857c51bb6121 (diff)
downloadnng-7bf591e20a94b8d926f92ab9b320f3b75d342345.tar.gz
nng-7bf591e20a94b8d926f92ab9b320f3b75d342345.tar.bz2
nng-7bf591e20a94b8d926f92ab9b320f3b75d342345.zip
fixes #143 Protocols and transports should be "configurable"
This makes all the protocols and transports optional. All of them except ZeroTier are enabled by default, but you can now disable them (remove from the build) with cmake options. The test suite is modified so that tests still run as much as they can, but skip over things caused by missing functionality from the library (due to configuration). Further, the constant definitions and prototypes for functions that are specific to transports or protocols are moved into appropriate headers, which should be included directly by applications wishing to use these. We have also added and improved documentation -- all of the transports are documented, and several more man pages for protocols have been added. (Req/Rep and Surveyor are still missing.)
Diffstat (limited to 'src/core')
-rw-r--r--src/core/msgqueue.c1
-rw-r--r--src/core/protocol.h35
-rw-r--r--src/core/socket.c1
-rw-r--r--src/core/transport.c40
4 files changed, 54 insertions, 23 deletions
diff --git a/src/core/msgqueue.c b/src/core/msgqueue.c
index 3f1ffcb5..10bffaa4 100644
--- a/src/core/msgqueue.c
+++ b/src/core/msgqueue.c
@@ -297,7 +297,6 @@ nni_msgq_run_getq(nni_msgq *mq)
static void
nni_msgq_run_notify(nni_msgq *mq)
{
- nni_aio *aio;
if (mq->mq_cb_fn != NULL) {
int flags = 0;
diff --git a/src/core/protocol.h b/src/core/protocol.h
index 5db259f0..39bde059 100644
--- a/src/core/protocol.h
+++ b/src/core/protocol.h
@@ -147,21 +147,26 @@ extern int nni_proto_open(nng_socket *, const nni_proto *);
// Protocol numbers are never more than 16 bits. Also, there will never be
// a valid protocol numbered 0 (NNG_PROTO_NONE).
#define NNI_PROTO(major, minor) (((major) *16) + (minor))
-enum nng_proto_enum {
- NNI_PROTO_NONE = NNI_PROTO(0, 0),
- NNI_PROTO_PAIR_V0 = NNI_PROTO(1, 0),
- NNI_PROTO_PAIR_V1 = NNI_PROTO(1, 1),
- NNI_PROTO_PUB_V0 = NNI_PROTO(2, 0),
- NNI_PROTO_SUB_V0 = NNI_PROTO(2, 1),
- NNI_PROTO_REQ_V0 = NNI_PROTO(3, 0),
- NNI_PROTO_REP_V0 = NNI_PROTO(3, 1),
- NNI_PROTO_PUSH_V0 = NNI_PROTO(5, 0),
- NNI_PROTO_PULL_V0 = NNI_PROTO(5, 1),
- NNI_PROTO_SURVEYOR_V0 = NNI_PROTO(6, 2),
- NNI_PROTO_RESPONDENT_V0 = NNI_PROTO(6, 3),
- NNI_PROTO_BUS_V0 = NNI_PROTO(7, 0),
- NNI_PROTO_STAR_V0 = NNI_PROTO(100, 0),
-};
+
+// Protocol major numbers. This is here for documentation only, and
+// to serve as a "registry" for managing new protocol numbers. Consider
+// updating this table when adding new protocols.
+//
+// Protocol Maj Min Name Notes
+// -------------------------------------------
+// NONE 0 0 reserved
+// PAIRv0 1 0 pair
+// PAIRv1 1 1 pair1 nng only, experimental
+// PUBv0 2 0 pub
+// SUBv0 2 1 sub
+// REQv0 3 0 req
+// REPv0 3 1 rep
+// PUSHv0 5 0 push
+// PULLv0 5 1 pull
+// SURVEYORv0 6 2 surveyor minors 0 & 1 retired
+// RESPONDENTv0 6 3 respondent
+// BUSv0 7 0 bus
+// STARv0 100 0 star mangos only, experimental
extern int nni_proto_sys_init(void);
extern void nni_proto_sys_fini(void);
diff --git a/src/core/socket.c b/src/core/socket.c
index c9b70ccb..4a84b639 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -102,7 +102,6 @@ static int
nni_sock_getopt_fd(nni_sock *s, int flag, void *val, size_t *szp)
{
int rv;
- uint32_t flags;
nni_notifyfd *fd;
nni_msgq * mq;
nni_msgq_cb cb;
diff --git a/src/core/transport.c b/src/core/transport.c
index 6dcf4538..af9c93fb 100644
--- a/src/core/transport.c
+++ b/src/core/transport.c
@@ -10,6 +10,9 @@
#include "core/nng_impl.h"
#include "transport/inproc/inproc.h"
+#include "transport/ipc/ipc.h"
+#include "transport/tcp/tcp.h"
+#include "transport/zerotier/zerotier.h"
#include <stdio.h>
#include <string.h>
@@ -51,6 +54,11 @@ nni_tran_register(const nni_tran *tran)
nni_mtx_lock(&nni_tran_lk);
// Check to see if the transport is already registered...
NNI_LIST_FOREACH (&nni_tran_list, t) {
+ if (tran->tran_init == t->t_tran.tran_init) {
+ nni_mtx_unlock(&nni_tran_lk);
+ // Same transport, duplicate registration.
+ return (0);
+ }
if (strcmp(tran->tran_scheme, t->t_tran.tran_scheme) == 0) {
nni_mtx_unlock(&nni_tran_lk);
return (NNG_ESTATE);
@@ -129,20 +137,40 @@ nni_tran_chkopt(const char *name, const void *v, size_t sz)
// nni_tran_sys_init initializes the entire transport subsystem, including
// each individual transport.
+
+typedef int (*nni_tran_ctor)(void);
+
+static nni_tran_ctor nni_tran_ctors[] = {
+#ifdef NNG_HAVE_INPROC
+ nng_inproc_register,
+#endif
+#ifdef NNG_HAVE_IPC
+ nng_ipc_register,
+#endif
+#ifdef NNG_HAVE_TCP
+ nng_tcp_register,
+#endif
+#ifdef NNI_HAVE_ZEROTIER
+ nng_zt_register,
+#endif
+ NULL,
+};
+
int
nni_tran_sys_init(void)
{
- int rv;
+ int i;
nni_tran_inited = 1;
NNI_LIST_INIT(&nni_tran_list, nni_transport, t_node);
nni_mtx_init(&nni_tran_lk);
- if (((rv = nng_inproc_register()) != 0) ||
- ((rv = nni_tran_register(&nni_ipc_tran)) != 0) ||
- ((rv = nni_tran_register(&nni_tcp_tran)) != 0)) {
- nni_tran_sys_fini();
- return (rv);
+ for (i = 0; nni_tran_ctors[i] != NULL; i++) {
+ int rv;
+ if ((rv = (nni_tran_ctors[i])()) != 0) {
+ nni_tran_sys_fini();
+ return (rv);
+ }
}
return (0);
}