diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-08-17 11:49:16 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-08-17 11:49:16 -0700 |
| commit | 76c1fc80c931b086493835d037245ebbb5f8d406 (patch) | |
| tree | e33b7765f755f7497eff26a9458c09ebe1da94ff /src/core/transport.c | |
| parent | a9633313ec8e578c805cd53b37ba3360d83157bc (diff) | |
| download | nng-76c1fc80c931b086493835d037245ebbb5f8d406.tar.gz nng-76c1fc80c931b086493835d037245ebbb5f8d406.tar.bz2 nng-76c1fc80c931b086493835d037245ebbb5f8d406.zip | |
fixes #39 Transport ops vector should be versioned
This also includes tests for some of the edge cases surrounding
pluggable transports, such as version mismatch, duplication registration,
and failure to initialize.
Diffstat (limited to 'src/core/transport.c')
| -rw-r--r-- | src/core/transport.c | 15 |
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; } |
