aboutsummaryrefslogtreecommitdiff
path: root/src/core/transport.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/transport.c')
-rw-r--r--src/core/transport.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/core/transport.c b/src/core/transport.c
index 6f73a6b2..2f373f9a 100644
--- a/src/core/transport.c
+++ b/src/core/transport.c
@@ -27,6 +27,7 @@ typedef struct nni_transport {
static nni_list nni_tran_list;
static nni_mtx nni_tran_lk;
+static int nni_tran_inited;
int
nni_tran_register(const nni_tran *tran)
@@ -34,6 +35,18 @@ nni_tran_register(const nni_tran *tran)
nni_transport *t;
int rv;
+ // Its entirely possible that we are called before any sockets
+ // are opened. Make sure we are initialized. This has to be
+ // protected by a guard to prevent infinite recursion, since
+ // nni_init also winds up calling us.
+ if (!nni_tran_inited) {
+ nni_init();
+ }
+
+ if (tran->tran_version != NNI_TRANSPORT_VERSION) {
+ return (NNG_ENOTSUP);
+ }
+
nni_mtx_lock(&nni_tran_lk);
// Check to see if the transport is already registered...
NNI_LIST_FOREACH (&nni_tran_list, t) {
@@ -83,6 +96,7 @@ nni_tran_sys_init(void)
{
int rv;
+ nni_tran_inited = 1;
NNI_LIST_INIT(&nni_tran_list, nni_transport, t_node);
nni_mtx_init(&nni_tran_lk);
@@ -108,4 +122,5 @@ nni_tran_sys_fini(void)
NNI_FREE_STRUCT(t);
}
nni_mtx_fini(&nni_tran_lk);
+ nni_tran_inited = 0;
}