From 4998964a435fe0f02a2d81b01fdb837214674e72 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 30 Apr 2018 21:41:40 -0700 Subject: fixes #381 Want comparators for various types --- src/nng.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 16 deletions(-) (limited to 'src/nng.c') diff --git a/src/nng.c b/src/nng.c index a4b8fd27..4dc6c3fa 100644 --- a/src/nng.c +++ b/src/nng.c @@ -46,6 +46,12 @@ nng_close(nng_socket s) return (rv); } +int +nng_socket_id(nng_socket s) +{ + return (((int) s.id > 0) ? (int) s.id : -1); +} + void nng_closeall(void) { @@ -230,12 +236,12 @@ nng_send_aio(nng_socket s, nng_aio *aio) } int -nng_ctx_open(nng_ctx *idp, nng_socket s) +nng_ctx_open(nng_ctx *cp, nng_socket s) { nni_sock *sock; nni_ctx * ctx; int rv; - nng_ctx id; + nng_ctx c; if ((rv = nni_sock_find(&sock, s.id)) != 0) { return (rv); @@ -244,20 +250,20 @@ nng_ctx_open(nng_ctx *idp, nng_socket s) nni_sock_rele(sock); return (rv); } - id.id = nni_ctx_id(ctx); - *idp = id; + c.id = nni_ctx_id(ctx); nni_ctx_rele(ctx); nni_sock_rele(sock); + *cp = c; return (0); } int -nng_ctx_close(nng_ctx cid) +nng_ctx_close(nng_ctx c) { int rv; nni_ctx *ctx; - if ((rv = nni_ctx_find(&ctx, cid.id, true)) != 0) { + if ((rv = nni_ctx_find(&ctx, c.id, true)) != 0) { return (rv); } // no release, close releases implicitly. @@ -265,6 +271,12 @@ nng_ctx_close(nng_ctx cid) return (0); } +int +nng_ctx_id(nng_ctx c) +{ + return (((int) c.id > 0) ? (int) c.id : -1); +} + void nng_ctx_recv(nng_ctx cid, nng_aio *aio) { @@ -496,6 +508,12 @@ nng_listener_start(nng_listener l, int flags) return (rv); } +int +nng_listener_id(nng_listener l) +{ + return (((int) l.id > 0) ? (int) l.id : -1); +} + int nng_dialer_create(nng_dialer *dp, nng_socket s, const char *addr) { @@ -532,6 +550,12 @@ nng_dialer_start(nng_dialer d, int flags) return (rv); } +int +nng_dialer_id(nng_dialer d) +{ + return (((int) d.id > 0) ? (int) d.id : -1); +} + static int nng_ep_setx( uint32_t id, const char *n, const void *v, size_t sz, int mode, int t) @@ -1088,19 +1112,19 @@ nng_strerror(int num) } static int -nng_pipe_getx(nng_pipe id, const char *name, void *val, size_t *szp, int t) +nng_pipe_getx(nng_pipe p, const char *name, void *val, size_t *szp, int t) { int rv; - nni_pipe *p; + nni_pipe *pipe; if ((rv = nni_init()) < 0) { return (rv); } - if ((rv = nni_pipe_find(&p, id.id)) != 0) { + if ((rv = nni_pipe_find(&pipe, p.id)) != 0) { return (rv); } - rv = nni_pipe_getopt(p, name, val, szp, t); - nni_pipe_rele(p); + rv = nni_pipe_getopt(pipe, name, val, szp, t); + nni_pipe_rele(pipe); return (rv); } @@ -1167,19 +1191,25 @@ nng_pipe_getopt_string(nng_pipe p, const char *name, char **valp) } int -nng_pipe_close(nng_pipe pid) +nng_pipe_close(nng_pipe p) { int rv; - nni_pipe *p; + nni_pipe *pipe; - if ((rv = nni_pipe_find(&p, pid.id)) != 0) { + if ((rv = nni_pipe_find(&pipe, p.id)) != 0) { return (rv); } - nni_pipe_close(p); - nni_pipe_rele(p); + nni_pipe_close(pipe); + nni_pipe_rele(pipe); return (0); } +int +nng_pipe_id(nng_pipe p) +{ + return (((int) p.id > 0) ? (int) p.id : -1); +} + // Message handling. int nng_msg_alloc(nng_msg **msgp, size_t size) -- cgit v1.2.3-70-g09d2