diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-21 17:40:04 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-21 17:40:04 -0800 |
| commit | 568a84ed2d3d41da5ca64cde15a677237fffd991 (patch) | |
| tree | 92ee212c0c8f4dc264acd0cef33285bddefd5a93 /tests/event.c | |
| parent | 434cdd9f4e9211b99ba62ff6973e082b90e098f0 (diff) | |
| download | nng-568a84ed2d3d41da5ca64cde15a677237fffd991.tar.gz nng-568a84ed2d3d41da5ca64cde15a677237fffd991.tar.bz2 nng-568a84ed2d3d41da5ca64cde15a677237fffd991.zip | |
Fix leaks in bus, socket leaks, tighten up close-side refcnting.
This does a few things. First it closes some preexisting leaks.
Second it tightens the overall close logic so that we automatically
discard idhash resources (while keeping numeric values for next id
etc. around) when the last socket is closed. This then eliminates
the need for applications to ever explicitly terminate resources.
It turns out platform-specific resources established at nni_init()
time might still be leaked, but it's also the case that we now no
longer dynamically allocate anything at platform initialization time.
(This presumes that the platform doesn't do so under the hood when
creating critical sections or mutexes for example.)
Diffstat (limited to 'tests/event.c')
| -rw-r--r-- | tests/event.c | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/tests/event.c b/tests/event.c index 30e8f438..554f990f 100644 --- a/tests/event.c +++ b/tests/event.c @@ -9,8 +9,8 @@ #include "convey.h" #include "nng.h" -#include "core/nng_impl.h" #include <string.h> +#include <assert.h> #define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s)) #define CHECKSTR(m, s) So(nng_msg_len(m) == strlen(s));\ @@ -31,10 +31,7 @@ bump(nng_event *ev, void *arg) { struct evcnt *cnt = arg; - if (nng_event_socket(ev) != cnt->sock) { - nni_panic("Incorrect socket! %p != %p", - nng_event_socket(ev), cnt->sock); - } + assert(nng_event_socket(ev) == cnt->sock); switch (nng_event_type(ev)) { case NNG_EV_CAN_SEND: cnt->writeable++; @@ -61,7 +58,7 @@ bump(nng_event *ev, void *arg) break; default: - nni_panic("Invalid event type %d", nng_event_type(ev)); + assert(0); break; } } @@ -69,8 +66,6 @@ bump(nng_event *ev, void *arg) Main({ const char *addr = "inproc://test"; - nni_init(); - Test("Event Handling", { Convey("Given a connected pair of pair sockets", { nng_socket sock1; @@ -97,26 +92,26 @@ Main({ So(nng_dial(sock2, addr, NULL, NNG_FLAG_SYNCH) == 0); // Let everything connect. - nni_usleep(100000); + nng_usleep(100000); Convey("We can register callbacks", { So((notify1 = nng_setnotify(sock1, NNG_EV_CAN_SEND, bump, &evcnt1)) != NULL); So((notify2 = nng_setnotify(sock2, NNG_EV_CAN_RECV, bump, &evcnt2)) != NULL); Convey("They are called", { - nni_msg *msg; + nng_msg *msg; - So(nni_msg_alloc(&msg, 0) == 0); + So(nng_msg_alloc(&msg, 0) == 0); APPENDSTR(msg, "abc"); So(nng_sendmsg(sock1, msg, 0) == 0); So(nng_recvmsg(sock2, &msg, 0) == 0); CHECKSTR(msg, "abc"); - nni_msg_free(msg); + nng_msg_free(msg); // The notify runs async... - nni_usleep(100000); + nng_usleep(100000); So(evcnt1.writeable == 1); So(evcnt2.readable == 1); @@ -131,6 +126,4 @@ Main({ }) }) }) - - nni_fini(); }) |
