aboutsummaryrefslogtreecommitdiff
path: root/src/core/transport.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-07 16:12:41 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-07 16:12:41 -0700
commit22d991fda77578dd03c8d477f8427631e6383cee (patch)
treec81eb35a13fbeb1dab8f8e6ca62dc8ccf42636e0 /src/core/transport.c
parentc5354ea49184a359df8d477e844b1c52aeb234d5 (diff)
downloadnng-22d991fda77578dd03c8d477f8427631e6383cee.tar.gz
nng-22d991fda77578dd03c8d477f8427631e6383cee.tar.bz2
nng-22d991fda77578dd03c8d477f8427631e6383cee.zip
Subsystem initialize is idempotent; simplify cleanup.
Diffstat (limited to 'src/core/transport.c')
-rw-r--r--src/core/transport.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/core/transport.c b/src/core/transport.c
index 61b1a0c3..ff72c754 100644
--- a/src/core/transport.c
+++ b/src/core/transport.c
@@ -1,5 +1,6 @@
//
-// Copyright 2016 Garrett D'Amore <garrett@damore.org>
+// 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
@@ -50,15 +51,19 @@ nni_tran_find(const char *addr)
// nni_tran_sys_init initializes the entire transport subsystem, including
// each individual transport.
-void
+int
nni_tran_sys_init(void)
{
- int i;
nni_tran *tran;
- for (i = 0; (tran = transports[i]) != NULL; i++) {
- tran->tran_init();
+ for (int i = 0; (tran = transports[i]) != NULL; i++) {
+ int rv;
+ if ((rv = tran->tran_init()) != 0) {
+ nni_tran_sys_fini();
+ return (rv);
+ }
}
+ return (0);
}
// nni_tran_sys_fini finalizes the entire transport system, including all
@@ -66,10 +71,9 @@ nni_tran_sys_init(void)
void
nni_tran_sys_fini(void)
{
- int i;
nni_tran *tran;
- for (i = 0; (tran = transports[i]) != NULL; i++) {
+ for (int i = 0; (tran = transports[i]) != NULL; i++) {
if (tran->tran_fini != NULL) {
tran->tran_fini();
}