diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-04-30 21:41:40 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-05-01 12:27:19 -0700 |
| commit | 4998964a435fe0f02a2d81b01fdb837214674e72 (patch) | |
| tree | dc5fe29da0574fc1510ab6f9b23b54ffd68cd97b /src/nng.c | |
| parent | 63bdb2c28bc185096e579d1922d57cb71ecaa36b (diff) | |
| download | nng-4998964a435fe0f02a2d81b01fdb837214674e72.tar.gz nng-4998964a435fe0f02a2d81b01fdb837214674e72.tar.bz2 nng-4998964a435fe0f02a2d81b01fdb837214674e72.zip | |
fixes #381 Want comparators for various types
Diffstat (limited to 'src/nng.c')
| -rw-r--r-- | src/nng.c | 62 |
1 files changed, 46 insertions, 16 deletions
@@ -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) { @@ -497,6 +509,12 @@ nng_listener_start(nng_listener l, int flags) } 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) { nni_sock * sock; @@ -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) |
