diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-27 01:15:46 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-27 01:15:46 -0800 |
| commit | 82e058a2abae40760f0f9956cdb9d21f8a512624 (patch) | |
| tree | a2aa52cb91afea0224657ef8bc32d61de2adc3fc /src/nng.c | |
| parent | 0867d597788099c213b1f3b0bbd2f3adbaeceee2 (diff) | |
| download | nng-82e058a2abae40760f0f9956cdb9d21f8a512624.tar.gz nng-82e058a2abae40760f0f9956cdb9d21f8a512624.tar.bz2 nng-82e058a2abae40760f0f9956cdb9d21f8a512624.zip | |
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.
Diffstat (limited to 'src/nng.c')
| -rw-r--r-- | src/nng.c | 34 |
1 files changed, 26 insertions, 8 deletions
@@ -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); } |
