diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-05-02 16:01:22 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-05-03 06:41:19 -0700 |
| commit | 159dc95695515db767e208c41d5f44b334b71adc (patch) | |
| tree | 5390251d939c33b1d274d0767861d2012673e258 /src/nng.c | |
| parent | 649e5d5ca9a03cef766e944c7735aab50041c012 (diff) | |
| download | nng-159dc95695515db767e208c41d5f44b334b71adc.tar.gz nng-159dc95695515db767e208c41d5f44b334b71adc.tar.bz2 nng-159dc95695515db767e208c41d5f44b334b71adc.zip | |
fixes #389 Need pipe notification callbacks
This adds a new pipe event notification API (callbacks called
on either pipe add or remove), including both tests and docs.
Also supporting APIs to get the socket or endpoint associated
with a pipe are included (tested and documented as well.)
Diffstat (limited to 'src/nng.c')
| -rw-r--r-- | src/nng.c | 59 |
1 files changed, 59 insertions, 0 deletions
@@ -1015,6 +1015,24 @@ nng_getopt_string(nng_socket s, const char *name, char **valp) } int +nng_pipe_notify(nng_socket s, nng_pipe_cb cb, void *arg) +{ + int rv; + nni_sock *sock; + + if ((rv = nni_init()) != 0) { + return (rv); + } + if ((rv = nni_sock_find(&sock, s.id)) != 0) { + return (rv); + } + + nni_sock_set_pipe_cb(sock, cb, arg); + nni_sock_rele(sock); + return (0); +} + +int nng_device(nng_socket s1, nng_socket s2) { int rv; @@ -1190,6 +1208,47 @@ nng_pipe_getopt_string(nng_pipe p, const char *name, char **valp) return (nng_pipe_getx(p, name, valp, &sz, NNI_TYPE_STRING)); } +nng_socket +nng_pipe_socket(nng_pipe p) +{ + nng_socket s = NNG_SOCKET_INITIALIZER; + nni_pipe * pipe; + + if ((nni_init() == 0) && (nni_pipe_find(&pipe, p.id) == 0)) { + s.id = nni_pipe_sock_id(pipe); + nni_pipe_rele(pipe); + } + return (s); +} + +nng_dialer +nng_pipe_dialer(nng_pipe p) +{ + nng_dialer d = NNG_DIALER_INITIALIZER; + nni_pipe * pipe; + if ((nni_init() == 0) && (nni_pipe_find(&pipe, p.id) == 0)) { + if (nni_pipe_ep_mode(pipe) == NNI_EP_MODE_DIAL) { + d.id = nni_pipe_ep_id(pipe); + } + nni_pipe_rele(pipe); + } + return (d); +} + +nng_listener +nng_pipe_listener(nng_pipe p) +{ + nng_listener l = NNG_LISTENER_INITIALIZER; + nni_pipe * pipe; + if ((nni_init() == 0) && (nni_pipe_find(&pipe, p.id) == 0)) { + if (nni_pipe_ep_mode(pipe) == NNI_EP_MODE_LISTEN) { + l.id = nni_pipe_ep_id(pipe); + } + nni_pipe_rele(pipe); + } + return (l); +} + int nng_pipe_close(nng_pipe p) { |
