From 82e058a2abae40760f0f9956cdb9d21f8a512624 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 27 Jan 2017 01:15:46 -0800 Subject: Add device support & testing. Bus semantic fix. This adds nn_device and nng_device. There were some internal changes required to fix shutdown / close issues. Note that we shut down the sockets when exiting from device -- this is required to make both threads see the failure and bail, since we are not using a single event loop. I also noticed that the bus protocol had a bug where it would send messages back to the originator. This was specifically tested for in the compat_device test, and we have fixed it. --- src/nng.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'src/nng.c') diff --git a/src/nng.c b/src/nng.c index d77a05c7..38d259fd 100644 --- a/src/nng.c +++ b/src/nng.c @@ -348,6 +348,30 @@ nng_event_type(nng_event *ev) } +int +nng_device(nng_socket s1, nng_socket s2) +{ + int rv; + nni_sock *sock1 = NULL; + nni_sock *sock2 = NULL; + + if ((s1 > 0) && (s1 != (nng_socket)-1)) { + if ((rv = nni_sock_hold(&sock1, s1)) != 0) { + return (rv); + } + } + if (((s2 > 0) && (s2 != (nng_socket)-1)) && (s2 != s1)) { + if ((rv = nni_sock_hold(&sock2, s2)) != 0) { + nni_sock_rele(sock1); + return (rv); + } + } + + rv = nni_device(sock1, sock2); + return (rv); +} + + // Misc. const char * nng_strerror(int num) @@ -617,14 +641,6 @@ nng_stat_value(nng_stat *stat) } -int -nng_device(nng_socket sock1, nng_socket sock2) -{ - // Device TBD. - return (NNG_ENOTSUP); -} - - // These routines exist as utility functions, exposing some of our "guts" // to the external world for the purposes of test code and bundled utilities. // They should not be considered part of our public API, and applications @@ -653,6 +669,8 @@ nng_thread_create(void **thrp, void (*func)(void *), void *arg) nni_thr *thr; int rv; + nni_init(); + if ((thr = NNI_ALLOC_STRUCT(thr)) == NULL) { return (NNG_ENOMEM); } -- cgit v1.2.3-70-g09d2