diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/endpt.c | 12 | ||||
| -rw-r--r-- | src/core/options.c | 206 | ||||
| -rw-r--r-- | src/core/options.h | 42 | ||||
| -rw-r--r-- | src/core/pipe.c | 6 | ||||
| -rw-r--r-- | src/core/protocol.h | 2 | ||||
| -rw-r--r-- | src/core/socket.c | 96 | ||||
| -rw-r--r-- | src/core/transport.h | 4 | ||||
| -rw-r--r-- | src/nng.c | 40 | ||||
| -rw-r--r-- | src/nng.h | 23 | ||||
| -rw-r--r-- | src/protocol/bus0/bus.c | 4 | ||||
| -rw-r--r-- | src/protocol/pair0/pair.c | 4 | ||||
| -rw-r--r-- | src/protocol/pair1/pair.c | 12 | ||||
| -rw-r--r-- | src/protocol/pipeline0/pull.c | 4 | ||||
| -rw-r--r-- | src/protocol/pipeline0/push.c | 4 | ||||
| -rw-r--r-- | src/protocol/pubsub0/pub.c | 4 | ||||
| -rw-r--r-- | src/protocol/pubsub0/sub.c | 4 | ||||
| -rw-r--r-- | src/protocol/reqrep0/rep.c | 8 | ||||
| -rw-r--r-- | src/protocol/reqrep0/req.c | 12 | ||||
| -rw-r--r-- | src/protocol/survey0/respond.c | 8 | ||||
| -rw-r--r-- | src/protocol/survey0/survey.c | 12 | ||||
| -rw-r--r-- | src/transport/inproc/inproc.c | 4 | ||||
| -rw-r--r-- | src/transport/ipc/ipc.c | 12 | ||||
| -rw-r--r-- | src/transport/tcp/tcp.c | 22 | ||||
| -rw-r--r-- | src/transport/tls/tls.c | 30 | ||||
| -rw-r--r-- | src/transport/ws/websocket.c | 28 | ||||
| -rw-r--r-- | src/transport/zerotier/zerotier.c | 82 |
26 files changed, 375 insertions, 310 deletions
diff --git a/src/core/endpt.c b/src/core/endpt.c index 131ee1db..d4bc9b01 100644 --- a/src/core/endpt.c +++ b/src/core/endpt.c @@ -649,12 +649,8 @@ nni_ep_getopt(nni_ep *ep, const char *name, void *valp, size_t *szp, int t) if (eo->eo_getopt == NULL) { return (NNG_EWRITEONLY); } - if ((t != NNI_TYPE_OPAQUE) && - (eo->eo_type != NNI_TYPE_OPAQUE) && (t != eo->eo_type)) { - return (NNG_EBADTYPE); - } nni_mtx_lock(&ep->ep_mtx); - rv = eo->eo_getopt(ep->ep_data, valp, szp); + rv = eo->eo_getopt(ep->ep_data, valp, szp, t); nni_mtx_unlock(&ep->ep_mtx); return (rv); } @@ -663,11 +659,7 @@ nni_ep_getopt(nni_ep *ep, const char *name, void *valp, size_t *szp, int t) // override. This allows the URL to be created with wildcards, // that are resolved later. if (strcmp(name, NNG_OPT_URL) == 0) { - if (t != NNI_TYPE_OPAQUE) { - // XXX: Add NNI_TYPE_STRING. - return (NNG_EBADTYPE); - } - return (nni_getopt_str(ep->ep_url->u_rawurl, valp, szp)); + return (nni_copyout_str(ep->ep_url->u_rawurl, valp, szp, t)); } return (nni_sock_getopt(ep->ep_sock, name, valp, szp, t)); diff --git a/src/core/options.c b/src/core/options.c index f51a6abe..9410de5f 100644 --- a/src/core/options.c +++ b/src/core/options.c @@ -129,140 +129,166 @@ nni_setopt_size(size_t *sp, const void *v, size_t sz, size_t minv, size_t maxv) } int -nni_getopt_ms(nni_duration u, void *val, size_t *sizep) +nni_setopt_buf(nni_msgq *mq, const void *val, size_t sz) { - size_t sz = sizeof(u); + int len; - if (sz > *sizep) { - sz = *sizep; + if (sz < sizeof(len)) { + return (NNG_EINVAL); } - *sizep = sizeof(u); - memcpy(val, &u, sz); - return (0); + memcpy(&len, val, sizeof(len)); + if (len < 0) { + return (NNG_EINVAL); + } + if (len > 8192) { + // put a reasonable uppper limit on queue depth. + // This is a count in messages, so the total queue + // size could be quite large indeed in this case. + return (NNG_EINVAL); + } + return (nni_msgq_resize(mq, len)); } int -nni_getopt_sockaddr(const nng_sockaddr *sa, void *val, size_t *sizep) +nni_copyout(const void *src, size_t srcsz, void *dst, size_t *dstszp) { - size_t sz = sizeof(*sa); - - if (sz > *sizep) { - sz = *sizep; + int rv = 0; + size_t copysz = *dstszp; + // Assumption is that this is type NNI_TYPE_OPAQUE. + if (copysz > srcsz) { + copysz = srcsz; + } else if (srcsz > copysz) { + // destination too small. + rv = NNG_EINVAL; } - *sizep = sizeof(*sa); - memcpy(val, sa, sz); - return (0); + *dstszp = srcsz; + memcpy(dst, src, copysz); + return (rv); } int -nni_getopt_int(int i, void *val, size_t *sizep) +nni_copyout_bool(bool b, void *dst, size_t *szp, int typ) { - size_t sz = sizeof(i); - - if (sz > *sizep) { - sz = *sizep; + switch (typ) { + case NNI_TYPE_BOOL: + NNI_ASSERT(*szp == sizeof(b)); + *(bool *) dst = b; + return (0); + case NNI_TYPE_OPAQUE: + return (nni_copyout(&b, sizeof(b), dst, szp)); + default: + return (NNG_EBADTYPE); } - *sizep = sizeof(i); - memcpy(val, &i, sz); - return (0); } int -nni_getopt_u64(uint64_t u, void *val, size_t *sizep) +nni_copyout_int(int i, void *dst, size_t *szp, int typ) { - size_t sz = sizeof(u); - - if (sz > *sizep) { - sz = *sizep; + switch (typ) { + case NNI_TYPE_INT32: + NNI_ASSERT(*szp == sizeof(i)); + *(int *) dst = i; + return (0); + case NNI_TYPE_OPAQUE: + return (nni_copyout(&i, sizeof(i), dst, szp)); + default: + return (NNG_EBADTYPE); } - *sizep = sizeof(u); - memcpy(val, &u, sz); - return (0); } int -nni_getopt_str(const char *ptr, void *val, size_t *sizep) +nni_copyout_ms(nng_duration d, void *dst, size_t *szp, int typ) { - size_t len = strlen(ptr) + 1; - size_t sz; - - sz = (len > *sizep) ? *sizep : len; - *sizep = len; - memcpy(val, ptr, sz); - return (0); + switch (typ) { + case NNI_TYPE_DURATION: + NNI_ASSERT(*szp == sizeof(d)); + *(nng_duration *) dst = d; + return (0); + case NNI_TYPE_OPAQUE: + return (nni_copyout(&d, sizeof(d), dst, szp)); + default: + return (NNG_EBADTYPE); + } } int -nni_getopt_size(size_t u, void *val, size_t *sizep) +nni_copyout_ptr(void *p, void *dst, size_t *szp, int typ) { - size_t sz = sizeof(u); - - if (sz > *sizep) { - sz = *sizep; + switch (typ) { + case NNI_TYPE_POINTER: + NNI_ASSERT(*szp == sizeof(p)); + *(void **) dst = p; + return (0); + case NNI_TYPE_OPAQUE: + return (nni_copyout(&p, sizeof(p), dst, szp)); + default: + return (NNG_EBADTYPE); } - *sizep = sizeof(u); - memcpy(val, &u, sz); - return (0); } int -nni_getopt_bool(bool b, void *val, size_t *sizep) +nni_copyout_size(size_t s, void *dst, size_t *szp, int typ) { - size_t sz = sizeof(b); - - if (sz > *sizep) { - sz = *sizep; + switch (typ) { + case NNI_TYPE_SIZE: + NNI_ASSERT(*szp == sizeof(s)); + *(size_t *) dst = s; + return (0); + case NNI_TYPE_OPAQUE: + return (nni_copyout(&s, sizeof(s), dst, szp)); + default: + return (NNG_EBADTYPE); } - *sizep = sizeof(b); - memcpy(val, &b, sz); - return (0); } int -nni_getopt_ptr(void *ptr, void *val, size_t *sizep) +nni_copyout_sockaddr(const nng_sockaddr *sap, void *dst, size_t *szp, int typ) { - size_t sz = sizeof(ptr); - - if (sz > *sizep) { - sz = *sizep; + switch (typ) { + case NNI_TYPE_SOCKADDR: + NNI_ASSERT(*szp == sizeof(*sap)); + *(nng_sockaddr *) dst = *sap; + return (0); + case NNI_TYPE_OPAQUE: + return (nni_copyout(sap, sizeof(*sap), dst, szp)); + default: + return (NNG_EBADTYPE); } - *sizep = sizeof(ptr); - memcpy(val, &ptr, sz); - return (0); } int -nni_setopt_buf(nni_msgq *mq, const void *val, size_t sz) +nni_copyout_u64(uint64_t u, void *dst, size_t *szp, int typ) { - int len; - - if (sz < sizeof(len)) { - return (NNG_EINVAL); + switch (typ) { + case NNI_TYPE_UINT64: + NNI_ASSERT(*szp == sizeof(u)); + *(uint64_t *) dst = u; + return (0); + case NNI_TYPE_OPAQUE: + return (nni_copyout(&u, sizeof(u), dst, szp)); + default: + return (NNG_EBADTYPE); } - memcpy(&len, val, sizeof(len)); - if (len < 0) { - return (NNG_EINVAL); - } - if (len > 8192) { - // put a reasonable uppper limit on queue depth. - // This is a count in messages, so the total queue - // size could be quite large indeed in this case. - return (NNG_EINVAL); - } - return (nni_msgq_resize(mq, len)); } int -nni_getopt_buf(nni_msgq *mq, void *val, size_t *sizep) +nni_copyout_str(const char *str, void *dst, size_t *szp, int typ) { - int len = nni_msgq_cap(mq); - - size_t sz = *sizep; - - if (sz > sizeof(len)) { - sz = sizeof(len); + char *s; + + switch (typ) { + case NNI_TYPE_STRING: + NNI_ASSERT(*szp == sizeof(char *)); + if ((s = nni_strdup(str)) == NULL) { + return (NNG_ENOMEM); + } + *(char **) dst = s; + return (0); + + case NNI_TYPE_OPAQUE: + return (nni_copyout(str, strlen(str) + 1, dst, szp)); + + default: + return (NNG_EBADTYPE); } - memcpy(val, &len, sz); - *sizep = sizeof(len); - return (0); -}
\ No newline at end of file +} diff --git a/src/core/options.h b/src/core/options.h index f5743aae..35c3232f 100644 --- a/src/core/options.h +++ b/src/core/options.h @@ -18,22 +18,13 @@ // nni_setopt_buf sets the queue size for the message queue. extern int nni_setopt_buf(nni_msgq *, const void *, size_t); -// nni_getopt_buf gets the queue size for the message queue. -extern int nni_getopt_buf(nni_msgq *, void *, size_t *); - // nni_setopt_duration sets the duration. Durations must be legal, // either a positive value, 0, or -1 to indicate forever. extern int nni_setopt_ms(nni_duration *, const void *, size_t); -// nni_getopt_duration gets the duration. -extern int nni_getopt_ms(nni_duration, void *, size_t *); - // nni_setopt_bool sets a bool, or _Bool extern int nni_setopt_bool(bool *, const void *, size_t); -// nni_getopt_bool gets a bool (or _Bool) -extern int nni_getopt_bool(bool, void *, size_t *); - // nni_setopt_int sets an integer, which must be between the minimum and // maximum values (inclusive). extern int nni_setopt_int(int *, const void *, size_t, int, int); @@ -41,18 +32,6 @@ extern int nni_setopt_int(int *, const void *, size_t, int, int); #define NNI_MAXINT ((int) 2147483647) #define NNI_MININT ((int) -2147483648) -// nni_getopt_int gets an integer. -extern int nni_getopt_int(int, void *, size_t *); - -// nni_getopt_u64 gets an unsigned 64 bit number. -extern int nni_getopt_u64(uint64_t, void *, size_t *); - -// nni_getopt_str gets a C style string. -extern int nni_getopt_str(const char *, void *, size_t *); - -// nni_getopt_sockaddr gets an nng_sockaddr. -extern int nni_getopt_sockaddr(const nng_sockaddr *, void *, size_t *); - // nni_setopt_size sets a size_t option. extern int nni_setopt_size(size_t *, const void *, size_t, size_t, size_t); @@ -61,15 +40,24 @@ extern int nni_setopt_size(size_t *, const void *, size_t, size_t, size_t); #define NNI_MINSZ (0) #define NNI_MAXSZ ((size_t) 0xffffffff) -// nni_getopt_size obtains a size_t option. -extern int nni_getopt_size(size_t, void *, size_t *); - -// nni_getopt_ptr obtains a pointer option. -extern int nni_getopt_ptr(void *, void *, size_t *); - extern int nni_chkopt_bool(size_t); extern int nni_chkopt_ms(const void *, size_t); extern int nni_chkopt_int(const void *, size_t, int, int); extern int nni_chkopt_size(const void *, size_t, size_t, size_t); +// nni_copyout_xxx copies out a type of the named value. It assumes that +// the type is aligned and the size correct, unless NNI_TYPE_OPAQUE is passed. +extern int nni_copyout(const void *, size_t, void *, size_t *); +extern int nni_copyout_bool(bool, void *, size_t *, int); +extern int nni_copyout_int(int, void *, size_t *, int); +extern int nni_copyout_ms(nng_duration, void *, size_t *, int); +extern int nni_copyout_ptr(void *, void *, size_t *, int); +extern int nni_copyout_size(size_t, void *, size_t *, int); +extern int nni_copyout_sockaddr(const nng_sockaddr *, void *, size_t *, int); +extern int nni_copyout_u64(uint64_t, void *, size_t *, int); + +// nni_copyout_str copies out a string. If the type is NNI_TYPE_STRING, +// then it passes through a pointer, created by nni_strdup(). +extern int nni_copyout_str(const char *, void *, size_t *, int); + #endif // CORE_OPTIONS_H diff --git a/src/core/pipe.c b/src/core/pipe.c index 40720906..a4148c65 100644 --- a/src/core/pipe.c +++ b/src/core/pipe.c @@ -297,11 +297,7 @@ nni_pipe_getopt(nni_pipe *p, const char *name, void *val, size_t *szp, int typ) if (strcmp(po->po_name, name) != 0) { continue; } - if ((typ != NNI_TYPE_OPAQUE) && - (po->po_type != NNI_TYPE_OPAQUE) && (typ != po->po_type)) { - return (NNG_EBADTYPE); - } - return (po->po_getopt(p->p_tran_data, val, szp)); + return (po->po_getopt(p->p_tran_data, val, szp, typ)); } // Maybe the endpoint knows? return (nni_ep_getopt(p->p_ep, name, val, szp, typ)); diff --git a/src/core/protocol.h b/src/core/protocol.h index e0e0e0d7..1c341241 100644 --- a/src/core/protocol.h +++ b/src/core/protocol.h @@ -50,7 +50,7 @@ struct nni_proto_pipe_ops { struct nni_proto_sock_option { const char *pso_name; int pso_type; - int (*pso_getopt)(void *, void *, size_t *); + int (*pso_getopt)(void *, void *, size_t *, int); int (*pso_setopt)(void *, const void *, size_t); }; diff --git a/src/core/socket.c b/src/core/socket.c index 40fdc9c8..9e98a9d9 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -22,7 +22,7 @@ static nni_mtx nni_sock_lk; typedef struct nni_socket_option { const char *so_name; int so_type; - int (*so_getopt)(nni_sock *, void *, size_t *); + int (*so_getopt)(nni_sock *, void *, size_t *, int); int (*so_setopt)(nni_sock *, const void *, size_t); } nni_socket_option; @@ -100,17 +100,13 @@ nni_sock_can_recv_cb(void *arg, int flags) } static int -nni_sock_getopt_fd(nni_sock *s, int flag, void *val, size_t *szp) +nni_sock_get_fd(nni_sock *s, int flag, int *fdp) { int rv; nni_notifyfd *fd; nni_msgq * mq; nni_msgq_cb cb; - if ((*szp < sizeof(int))) { - return (NNG_EINVAL); - } - if ((flag & nni_sock_flags(s)) == 0) { return (NNG_ENOTSUP); } @@ -131,35 +127,43 @@ nni_sock_getopt_fd(nni_sock *s, int flag, void *val, size_t *szp) return (NNG_EINVAL); } - // If we already inited this, just give back the same file descriptor. - if (fd->sn_init) { - memcpy(val, &fd->sn_rfd, sizeof(int)); - *szp = sizeof(int); - return (0); - } + // Open if not already done. + if (!fd->sn_init) { + if ((rv = nni_plat_pipe_open(&fd->sn_wfd, &fd->sn_rfd)) != 0) { + return (rv); + } - if ((rv = nni_plat_pipe_open(&fd->sn_wfd, &fd->sn_rfd)) != 0) { - return (rv); - } + nni_msgq_set_cb(mq, cb, fd); - nni_msgq_set_cb(mq, cb, fd); + fd->sn_init = 1; + } - fd->sn_init = 1; - *szp = sizeof(int); - memcpy(val, &fd->sn_rfd, sizeof(int)); + *fdp = fd->sn_rfd; return (0); } static int -nni_sock_getopt_sendfd(nni_sock *s, void *buf, size_t *szp) +nni_sock_getopt_sendfd(nni_sock *s, void *buf, size_t *szp, int typ) { - return (nni_sock_getopt_fd(s, NNI_PROTO_FLAG_SND, buf, szp)); + int fd; + int rv; + + if ((rv = nni_sock_get_fd(s, NNI_PROTO_FLAG_SND, &fd)) != 0) { + return (rv); + } + return (nni_copyout_int(fd, buf, szp, typ)); } static int -nni_sock_getopt_recvfd(nni_sock *s, void *buf, size_t *szp) +nni_sock_getopt_recvfd(nni_sock *s, void *buf, size_t *szp, int typ) { - return (nni_sock_getopt_fd(s, NNI_PROTO_FLAG_RCV, buf, szp)); + int fd; + int rv; + + if ((rv = nni_sock_get_fd(s, NNI_PROTO_FLAG_RCV, &fd)) != 0) { + return (rv); + } + return (nni_copyout_int(fd, buf, szp, typ)); } static int @@ -169,9 +173,9 @@ nni_sock_setopt_recvtimeo(nni_sock *s, const void *buf, size_t sz) } static int -nni_sock_getopt_recvtimeo(nni_sock *s, void *buf, size_t *szp) +nni_sock_getopt_recvtimeo(nni_sock *s, void *buf, size_t *szp, int typ) { - return (nni_getopt_ms(s->s_rcvtimeo, buf, szp)); + return (nni_copyout_ms(s->s_rcvtimeo, buf, szp, typ)); } static int @@ -181,9 +185,9 @@ nni_sock_setopt_sendtimeo(nni_sock *s, const void *buf, size_t sz) } static int -nni_sock_getopt_sendtimeo(nni_sock *s, void *buf, size_t *szp) +nni_sock_getopt_sendtimeo(nni_sock *s, void *buf, size_t *szp, int typ) { - return (nni_getopt_ms(s->s_sndtimeo, buf, szp)); + return (nni_copyout_ms(s->s_sndtimeo, buf, szp, typ)); } static int @@ -193,9 +197,9 @@ nni_sock_setopt_reconnmint(nni_sock *s, const void *buf, size_t sz) } static int -nni_sock_getopt_reconnmint(nni_sock *s, void *buf, size_t *szp) +nni_sock_getopt_reconnmint(nni_sock *s, void *buf, size_t *szp, int typ) { - return (nni_getopt_ms(s->s_reconn, buf, szp)); + return (nni_copyout_ms(s->s_reconn, buf, szp, typ)); } static int @@ -205,9 +209,9 @@ nni_sock_setopt_reconnmaxt(nni_sock *s, const void *buf, size_t sz) } static int -nni_sock_getopt_reconnmaxt(nni_sock *s, void *buf, size_t *szp) +nni_sock_getopt_reconnmaxt(nni_sock *s, void *buf, size_t *szp, int typ) { - return (nni_getopt_ms(s->s_reconnmax, buf, szp)); + return (nni_copyout_ms(s->s_reconnmax, buf, szp, typ)); } static int @@ -217,9 +221,11 @@ nni_sock_setopt_recvbuf(nni_sock *s, const void *buf, size_t sz) } static int -nni_sock_getopt_recvbuf(nni_sock *s, void *buf, size_t *szp) +nni_sock_getopt_recvbuf(nni_sock *s, void *buf, size_t *szp, int typ) { - return (nni_getopt_buf(s->s_urq, buf, szp)); + int len = nni_msgq_cap(s->s_urq); + + return (nni_copyout_int(len, buf, szp, typ)); } static int @@ -229,15 +235,17 @@ nni_sock_setopt_sendbuf(nni_sock *s, const void *buf, size_t sz) } static int -nni_sock_getopt_sendbuf(nni_sock *s, void *buf, size_t *szp) +nni_sock_getopt_sendbuf(nni_sock *s, void *buf, size_t *szp, int typ) { - return (nni_getopt_buf(s->s_uwq, buf, szp)); + int len = nni_msgq_cap(s->s_uwq); + + return (nni_copyout_int(len, buf, szp, typ)); } static int -nni_sock_getopt_sockname(nni_sock *s, void *buf, size_t *szp) +nni_sock_getopt_sockname(nni_sock *s, void *buf, size_t *szp, int typ) { - return (nni_getopt_str(s->s_name, buf, szp)); + return (nni_copyout_str(s->s_name, buf, szp, typ)); } static int @@ -1051,12 +1059,7 @@ nni_sock_getopt(nni_sock *s, const char *name, void *val, size_t *szp, int t) nni_mtx_unlock(&s->s_mx); return (NNG_EWRITEONLY); } - if ((pso->pso_type != NNI_TYPE_OPAQUE) && - (t != NNI_TYPE_OPAQUE) && (t != pso->pso_type)) { - nni_mtx_unlock(&s->s_mx); - return (NNG_EBADTYPE); - } - rv = pso->pso_getopt(s->s_data, val, szp); + rv = pso->pso_getopt(s->s_data, val, szp, t); nni_mtx_unlock(&s->s_mx); return (rv); } @@ -1070,12 +1073,7 @@ nni_sock_getopt(nni_sock *s, const char *name, void *val, size_t *szp, int t) nni_mtx_unlock(&s->s_mx); return (NNG_EWRITEONLY); } - if ((sso->so_type != NNI_TYPE_OPAQUE) && - (t != NNI_TYPE_OPAQUE) && (t != sso->so_type)) { - nni_mtx_unlock(&s->s_mx); - return (NNG_EBADTYPE); - } - rv = sso->so_getopt(s, val, szp); + rv = sso->so_getopt(s, val, szp, t); nni_mtx_unlock(&s->s_mx); return (rv); } diff --git a/src/core/transport.h b/src/core/transport.h index ebc14e83..7085126f 100644 --- a/src/core/transport.h +++ b/src/core/transport.h @@ -58,7 +58,7 @@ struct nni_tran_ep_option { int eo_type; // eo_getopt retrieves the value of the option. - int (*eo_getopt)(void *, void *, size_t *); + int (*eo_getopt)(void *, void *, size_t *, int); // eo_set sets the value of the option. If the first argument // (the endpoint) is NULL, then no actual set operation should be @@ -121,7 +121,7 @@ struct nni_tran_pipe_option { int po_type; // po_getopt retrieves the value of the option. - int (*po_getopt)(void *, void *, size_t *); + int (*po_getopt)(void *, void *, size_t *, int); }; // Pipe operations are entry points called by the socket. These may be called @@ -64,6 +64,18 @@ nng_free(void *buf, size_t sz) nni_free(buf, sz); } +char * +nng_strdup(const char *src) +{ + return (nni_strdup(src)); +} + +void +nng_strfree(char *s) +{ + nni_strfree(s); +} + int nng_recv(nng_socket sid, void *buf, size_t *szp, int flags) { @@ -482,6 +494,13 @@ nng_dialer_getopt_ptr(nng_dialer id, const char *name, void **vp) } int +nng_dialer_getopt_string(nng_dialer id, const char *name, char **vp) +{ + size_t sz = sizeof(*vp); + return (nng_dialer_getx(id, name, vp, &sz, NNI_TYPE_STRING)); +} + +int nng_dialer_getopt_ms(nng_dialer id, const char *name, nng_duration *vp) { size_t sz = sizeof(*vp); @@ -601,6 +620,13 @@ nng_listener_getopt_ptr(nng_listener id, const char *name, void **vp) } int +nng_listener_getopt_string(nng_listener id, const char *name, char **vp) +{ + size_t sz = sizeof(*vp); + return (nng_listener_getx(id, name, vp, &sz, NNI_TYPE_STRING)); +} + +int nng_listener_getopt_ms(nng_listener id, const char *name, nng_duration *vp) { size_t sz = sizeof(*vp); @@ -769,6 +795,13 @@ nng_getopt_ptr(nng_socket sid, const char *name, void **valp) } int +nng_getopt_string(nng_socket sid, const char *name, char **valp) +{ + size_t sz = sizeof(*valp); + return (nng_getx(sid, name, valp, &sz, NNI_TYPE_STRING)); +} + +int nng_device(nng_socket s1, nng_socket s2) { int rv; @@ -938,6 +971,13 @@ nng_pipe_getopt_sockaddr(nng_pipe id, const char *name, nng_sockaddr *sap) } int +nng_pipe_getopt_string(nng_pipe id, const char *name, char **valp) +{ + size_t sz = sizeof(*valp); + return (nng_pipe_getopt_x(id, name, valp, &sz, NNI_TYPE_STRING)); +} + +int nng_pipe_close(nng_pipe id) { int rv; @@ -178,6 +178,11 @@ NNG_DECL int nng_getopt_size(nng_socket, const char *, size_t *); NNG_DECL int nng_getopt_uint64(nng_socket, const char *, uint64_t *); NNG_DECL int nng_getopt_ptr(nng_socket, const char *, void **); +// nng_getopt_string is special -- it allocates a string to hold the +// resulting string, which should be freed with nng_strfree when it is +// no logner needed. +NNG_DECL int nng_getopt_string(nng_socket, const char *, char **); + // nng_listen creates a listening endpoint with no special options, // and starts it listening. It is functionally equivalent to the legacy // nn_bind(). The underlying endpoint is returned back to the caller in the @@ -242,6 +247,11 @@ NNG_DECL int nng_dialer_getopt_sockaddr( NNG_DECL int nng_dialer_getopt_uint64(nng_dialer, const char *, uint64_t *); NNG_DECL int nng_dialer_getopt_ptr(nng_dialer, const char *, void **); +// nng_dialer_getopt_string is special -- it allocates a string to hold the +// resulting string, which should be freed with nng_strfree when it is +// no logner needed. +NNG_DECL int nng_dialer_getopt_string(nng_dialer, const char *, char **); + // nng_listener_setopt sets an option for a dialer. This value is // not stored in the socket. Subsequent setopts on the socket may // override these value however. Note listener options may not be altered @@ -272,6 +282,11 @@ NNG_DECL int nng_listener_getopt_uint64( nng_listener, const char *, uint64_t *); NNG_DECL int nng_listener_getopt_ptr(nng_listener, const char *, void **); +// nng_listener_getopt_string is special -- it allocates a string to hold the +// resulting string, which should be freed with nng_strfree when it is +// no logner needed. +NNG_DECL int nng_listener_getopt_string(nng_listener, const char *, char **); + // nng_strerror returns a human readable string associated with the error // code supplied. NNG_DECL const char *nng_strerror(int); @@ -334,6 +349,13 @@ NNG_DECL void *nng_alloc(size_t); // calloc. NNG_DECL void nng_free(void *, size_t); +// nng_strdup duplicates the source string, using nng_alloc. The result +// should be freed with nng_strfree (or nng_free(strlen(s)+1)). +NNG_DECL char *nng_strdup(const char *); + +// nng_strfree is equivalent to nng_free(strlen(s)+1). +NNG_DECL void nng_strfree(char *); + // Async IO API. AIO structures can be thought of as "handles" to // support asynchronous operations. They contain the completion callback, and // a pointer to consumer data. This is similar to how overlapped I/O @@ -478,6 +500,7 @@ NNG_DECL int nng_pipe_getopt_size(nng_pipe, const char *, size_t *); NNG_DECL int nng_pipe_getopt_sockaddr(nng_pipe, const char *, nng_sockaddr *); NNG_DECL int nng_pipe_getopt_uint64(nng_pipe, const char *, uint64_t *); NNG_DECL int nng_pipe_getopt_ptr(nng_pipe, const char *, void **); +NNG_DECL int nng_pipe_getopt_string(nng_pipe, const char *, char **); NNG_DECL int nng_pipe_close(nng_pipe); // Flags. diff --git a/src/protocol/bus0/bus.c b/src/protocol/bus0/bus.c index 31b40fd5..00a9ca02 100644 --- a/src/protocol/bus0/bus.c +++ b/src/protocol/bus0/bus.c @@ -341,10 +341,10 @@ bus0_sock_setopt_raw(void *arg, const void *buf, size_t sz) } static int -bus0_sock_getopt_raw(void *arg, void *buf, size_t *szp) +bus0_sock_getopt_raw(void *arg, void *buf, size_t *szp, int typ) { bus0_sock *s = arg; - return (nni_getopt_bool(s->raw, buf, szp)); + return (nni_copyout_bool(s->raw, buf, szp, typ)); } static void diff --git a/src/protocol/pair0/pair.c b/src/protocol/pair0/pair.c index 476eadd6..bc8be866 100644 --- a/src/protocol/pair0/pair.c +++ b/src/protocol/pair0/pair.c @@ -239,10 +239,10 @@ pair0_sock_setopt_raw(void *arg, const void *buf, size_t sz) } static int -pair0_sock_getopt_raw(void *arg, void *buf, size_t *szp) +pair0_sock_getopt_raw(void *arg, void *buf, size_t *szp, int typ) { pair0_sock *s = arg; - return (nni_getopt_bool(s->raw, buf, szp)); + return (nni_copyout_bool(s->raw, buf, szp, typ)); } static void diff --git a/src/protocol/pair1/pair.c b/src/protocol/pair1/pair.c index 564118ae..ee67cf7b 100644 --- a/src/protocol/pair1/pair.c +++ b/src/protocol/pair1/pair.c @@ -408,10 +408,10 @@ pair1_sock_setopt_raw(void *arg, const void *buf, size_t sz) } static int -pair1_sock_getopt_raw(void *arg, void *buf, size_t *szp) +pair1_sock_getopt_raw(void *arg, void *buf, size_t *szp, int typ) { pair1_sock *s = arg; - return (nni_getopt_bool(s->raw, buf, szp)); + return (nni_copyout_bool(s->raw, buf, szp, typ)); } static int @@ -426,10 +426,10 @@ pair1_sock_setopt_maxttl(void *arg, const void *buf, size_t sz) } static int -pair1_sock_getopt_maxttl(void *arg, void *buf, size_t *szp) +pair1_sock_getopt_maxttl(void *arg, void *buf, size_t *szp, int typ) { pair1_sock *s = arg; - return (nni_getopt_int(s->ttl, buf, szp)); + return (nni_copyout_int(s->ttl, buf, szp, typ)); } static int @@ -444,10 +444,10 @@ pair1_sock_setopt_poly(void *arg, const void *buf, size_t sz) } static int -pair1_sock_getopt_poly(void *arg, void *buf, size_t *szp) +pair1_sock_getopt_poly(void *arg, void *buf, size_t *szp, int typ) { pair1_sock *s = arg; - return (nni_getopt_bool(s->poly, buf, szp)); + return (nni_copyout_bool(s->poly, buf, szp, typ)); } static void diff --git a/src/protocol/pipeline0/pull.c b/src/protocol/pipeline0/pull.c index fec07c39..d8f4641f 100644 --- a/src/protocol/pipeline0/pull.c +++ b/src/protocol/pipeline0/pull.c @@ -188,10 +188,10 @@ pull0_sock_setopt_raw(void *arg, const void *buf, size_t sz) } static int -pull0_sock_getopt_raw(void *arg, void *buf, size_t *szp) +pull0_sock_getopt_raw(void *arg, void *buf, size_t *szp, int typ) { pull0_sock *s = arg; - return (nni_getopt_bool(s->raw, buf, szp)); + return (nni_copyout_bool(s->raw, buf, szp, typ)); } static void diff --git a/src/protocol/pipeline0/push.c b/src/protocol/pipeline0/push.c index b6f6a824..bbffb433 100644 --- a/src/protocol/pipeline0/push.c +++ b/src/protocol/pipeline0/push.c @@ -205,10 +205,10 @@ push0_sock_setopt_raw(void *arg, const void *buf, size_t sz) } static int -push0_sock_getopt_raw(void *arg, void *buf, size_t *szp) +push0_sock_getopt_raw(void *arg, void *buf, size_t *szp, int typ) { push0_sock *s = arg; - return (nni_getopt_bool(s->raw, buf, szp)); + return (nni_copyout_bool(s->raw, buf, szp, typ)); } static void diff --git a/src/protocol/pubsub0/pub.c b/src/protocol/pubsub0/pub.c index 36c27e7f..3f4ecea6 100644 --- a/src/protocol/pubsub0/pub.c +++ b/src/protocol/pubsub0/pub.c @@ -281,10 +281,10 @@ pub0_sock_setopt_raw(void *arg, const void *buf, size_t sz) } static int -pub0_sock_getopt_raw(void *arg, void *buf, size_t *szp) +pub0_sock_getopt_raw(void *arg, void *buf, size_t *szp, int typ) { pub0_sock *s = arg; - return (nni_getopt_bool(s->raw, buf, szp)); + return (nni_copyout_bool(s->raw, buf, szp, typ)); } static void diff --git a/src/protocol/pubsub0/sub.c b/src/protocol/pubsub0/sub.c index cb7b0509..d7e9aea4 100644 --- a/src/protocol/pubsub0/sub.c +++ b/src/protocol/pubsub0/sub.c @@ -283,10 +283,10 @@ sub0_sock_setopt_raw(void *arg, const void *buf, size_t sz) } static int -sub0_sock_getopt_raw(void *arg, void *buf, size_t *szp) +sub0_sock_getopt_raw(void *arg, void *buf, size_t *szp, int typ) { sub0_sock *s = arg; - return (nni_getopt_bool(s->raw, buf, szp)); + return (nni_copyout_bool(s->raw, buf, szp, typ)); } static void diff --git a/src/protocol/reqrep0/rep.c b/src/protocol/reqrep0/rep.c index 429d55e7..5ee6c1be 100644 --- a/src/protocol/reqrep0/rep.c +++ b/src/protocol/reqrep0/rep.c @@ -365,10 +365,10 @@ rep0_sock_setopt_raw(void *arg, const void *buf, size_t sz) } static int -rep0_sock_getopt_raw(void *arg, void *buf, size_t *szp) +rep0_sock_getopt_raw(void *arg, void *buf, size_t *szp, int typ) { rep0_sock *s = arg; - return (nni_getopt_bool(s->raw, buf, szp)); + return (nni_copyout_bool(s->raw, buf, szp, typ)); } static int @@ -379,10 +379,10 @@ rep0_sock_setopt_maxttl(void *arg, const void *buf, size_t sz) } static int -rep0_sock_getopt_maxttl(void *arg, void *buf, size_t *szp) +rep0_sock_getopt_maxttl(void *arg, void *buf, size_t *szp, int typ) { rep0_sock *s = arg; - return (nni_getopt_int(s->ttl, buf, szp)); + return (nni_copyout_int(s->ttl, buf, szp, typ)); } static nni_msg * diff --git a/src/protocol/reqrep0/req.c b/src/protocol/reqrep0/req.c index 63ae07a0..659578d4 100644 --- a/src/protocol/reqrep0/req.c +++ b/src/protocol/reqrep0/req.c @@ -257,10 +257,10 @@ req0_sock_setopt_raw(void *arg, const void *buf, size_t sz) } static int -req0_sock_getopt_raw(void *arg, void *buf, size_t *szp) +req0_sock_getopt_raw(void *arg, void *buf, size_t *szp, int typ) { req0_sock *s = arg; - return (nni_getopt_bool(s->raw, buf, szp)); + return (nni_copyout_bool(s->raw, buf, szp, typ)); } static int @@ -271,10 +271,10 @@ req0_sock_setopt_maxttl(void *arg, const void *buf, size_t sz) } static int -req0_sock_getopt_maxttl(void *arg, void *buf, size_t *szp) +req0_sock_getopt_maxttl(void *arg, void *buf, size_t *szp, int typ) { req0_sock *s = arg; - return (nni_getopt_int(s->ttl, buf, szp)); + return (nni_copyout_int(s->ttl, buf, szp, typ)); } static int @@ -285,10 +285,10 @@ req0_sock_setopt_resendtime(void *arg, const void *buf, size_t sz) } static int -req0_sock_getopt_resendtime(void *arg, void *buf, size_t *szp) +req0_sock_getopt_resendtime(void *arg, void *buf, size_t *szp, int typ) { req0_sock *s = arg; - return (nni_getopt_ms(s->retry, buf, szp)); + return (nni_copyout_ms(s->retry, buf, szp, typ)); } // Raw and cooked mode differ in the way they send messages out. diff --git a/src/protocol/survey0/respond.c b/src/protocol/survey0/respond.c index 42db2cb0..035e51b1 100644 --- a/src/protocol/survey0/respond.c +++ b/src/protocol/survey0/respond.c @@ -359,10 +359,10 @@ resp0_sock_setopt_raw(void *arg, const void *buf, size_t sz) } static int -resp0_sock_getopt_raw(void *arg, void *buf, size_t *szp) +resp0_sock_getopt_raw(void *arg, void *buf, size_t *szp, int typ) { resp0_sock *s = arg; - return (nni_getopt_bool(s->raw, buf, szp)); + return (nni_copyout_bool(s->raw, buf, szp, typ)); } static int @@ -373,10 +373,10 @@ resp0_sock_setopt_maxttl(void *arg, const void *buf, size_t sz) } static int -resp0_sock_getopt_maxttl(void *arg, void *buf, size_t *szp) +resp0_sock_getopt_maxttl(void *arg, void *buf, size_t *szp, int typ) { resp0_sock *s = arg; - return (nni_getopt_int(s->ttl, buf, szp)); + return (nni_copyout_int(s->ttl, buf, szp, typ)); } static void diff --git a/src/protocol/survey0/survey.c b/src/protocol/survey0/survey.c index 40ace91b..161a5002 100644 --- a/src/protocol/survey0/survey.c +++ b/src/protocol/survey0/survey.c @@ -290,10 +290,10 @@ surv0_sock_setopt_raw(void *arg, const void *buf, size_t sz) } static int -surv0_sock_getopt_raw(void *arg, void *buf, size_t *szp) +surv0_sock_getopt_raw(void *arg, void *buf, size_t *szp, int typ) { surv0_sock *s = arg; - return (nni_getopt_bool(s->raw, buf, szp)); + return (nni_copyout_bool(s->raw, buf, szp, typ)); } static int @@ -304,10 +304,10 @@ surv0_sock_setopt_maxttl(void *arg, const void *buf, size_t sz) } static int -surv0_sock_getopt_maxttl(void *arg, void *buf, size_t *szp) +surv0_sock_getopt_maxttl(void *arg, void *buf, size_t *szp, int typ) { surv0_sock *s = arg; - return (nni_getopt_int(s->ttl, buf, szp)); + return (nni_copyout_int(s->ttl, buf, szp, typ)); } static int @@ -318,10 +318,10 @@ surv0_sock_setopt_surveytime(void *arg, const void *buf, size_t sz) } static int -surv0_sock_getopt_surveytime(void *arg, void *buf, size_t *szp) +surv0_sock_getopt_surveytime(void *arg, void *buf, size_t *szp, int typ) { surv0_sock *s = arg; - return (nni_getopt_ms(s->survtime, buf, szp)); + return (nni_copyout_ms(s->survtime, buf, szp, typ)); } static void diff --git a/src/transport/inproc/inproc.c b/src/transport/inproc/inproc.c index 14457623..e7253f7b 100644 --- a/src/transport/inproc/inproc.c +++ b/src/transport/inproc/inproc.c @@ -177,7 +177,7 @@ nni_inproc_pipe_peer(void *arg) } static int -nni_inproc_pipe_get_addr(void *arg, void *buf, size_t *szp) +nni_inproc_pipe_get_addr(void *arg, void *buf, size_t *szp, int typ) { nni_inproc_pipe *p = arg; nni_sockaddr sa; @@ -185,7 +185,7 @@ nni_inproc_pipe_get_addr(void *arg, void *buf, size_t *szp) memset(&sa, 0, sizeof(sa)); sa.s_inproc.sa_family = NNG_AF_INPROC; nni_strlcpy(sa.s_inproc.sa_name, p->addr, sizeof(sa.s_inproc.sa_name)); - return (nni_getopt_sockaddr(&sa, buf, szp)); + return (nni_copyout_sockaddr(&sa, buf, szp, typ)); } static int diff --git a/src/transport/ipc/ipc.c b/src/transport/ipc/ipc.c index 9f95c2a9..9d25ed72 100644 --- a/src/transport/ipc/ipc.c +++ b/src/transport/ipc/ipc.c @@ -490,10 +490,10 @@ nni_ipc_pipe_peer(void *arg) } static int -nni_ipc_pipe_get_addr(void *arg, void *buf, size_t *szp) +nni_ipc_pipe_get_addr(void *arg, void *buf, size_t *szp, int typ) { nni_ipc_pipe *p = arg; - return (nni_getopt_sockaddr(&p->sa, buf, szp)); + return (nni_copyout_sockaddr(&p->sa, buf, szp, typ)); } static void @@ -689,17 +689,17 @@ nni_ipc_ep_setopt_recvmaxsz(void *arg, const void *data, size_t sz) } static int -nni_ipc_ep_getopt_recvmaxsz(void *arg, void *data, size_t *szp) +nni_ipc_ep_getopt_recvmaxsz(void *arg, void *data, size_t *szp, int typ) { nni_ipc_ep *ep = arg; - return (nni_getopt_size(ep->rcvmax, data, szp)); + return (nni_copyout_size(ep->rcvmax, data, szp, typ)); } static int -nni_ipc_ep_get_addr(void *arg, void *data, size_t *szp) +nni_ipc_ep_get_addr(void *arg, void *data, size_t *szp, int typ) { nni_ipc_ep *ep = arg; - return (nni_getopt_sockaddr(&ep->sa, data, szp)); + return (nni_copyout_sockaddr(&ep->sa, data, szp, typ)); } static nni_tran_pipe_option nni_ipc_pipe_options[] = { diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c index 5741beea..4837c8d3 100644 --- a/src/transport/tcp/tcp.c +++ b/src/transport/tcp/tcp.c @@ -442,7 +442,7 @@ nni_tcp_pipe_peer(void *arg) } static int -nni_tcp_pipe_getopt_locaddr(void *arg, void *v, size_t *szp) +nni_tcp_pipe_getopt_locaddr(void *arg, void *v, size_t *szp, int typ) { nni_tcp_pipe *p = arg; int rv; @@ -450,13 +450,13 @@ nni_tcp_pipe_getopt_locaddr(void *arg, void *v, size_t *szp) memset(&sa, 0, sizeof(sa)); if ((rv = nni_plat_tcp_pipe_sockname(p->tpp, &sa)) == 0) { - rv = nni_getopt_sockaddr(&sa, v, szp); + rv = nni_copyout_sockaddr(&sa, v, szp, typ); } return (rv); } static int -nni_tcp_pipe_getopt_remaddr(void *arg, void *v, size_t *szp) +nni_tcp_pipe_getopt_remaddr(void *arg, void *v, size_t *szp, int typ) { nni_tcp_pipe *p = arg; int rv; @@ -464,7 +464,7 @@ nni_tcp_pipe_getopt_remaddr(void *arg, void *v, size_t *szp) memset(&sa, 0, sizeof(sa)); if ((rv = nni_plat_tcp_pipe_peername(p->tpp, &sa)) == 0) { - rv = nni_getopt_sockaddr(&sa, v, szp); + rv = nni_copyout_sockaddr(&sa, v, szp, typ); } return (rv); } @@ -736,7 +736,7 @@ nni_tcp_ep_setopt_recvmaxsz(void *arg, const void *v, size_t sz) } static int -nni_tcp_ep_getopt_url(void *arg, void *v, size_t *szp) +nni_tcp_ep_getopt_url(void *arg, void *v, size_t *szp, int typ) { nni_tcp_ep *ep = arg; char ustr[128]; @@ -744,18 +744,18 @@ nni_tcp_ep_getopt_url(void *arg, void *v, size_t *szp) char portstr[6]; // max for 16-bit port if (ep->mode == NNI_EP_MODE_DIAL) { - return (nni_getopt_str(ep->url->u_rawurl, v, szp)); + return (nni_copyout_str(ep->url->u_rawurl, v, szp, typ)); } nni_plat_tcp_ntop(&ep->bsa, ipstr, portstr); snprintf(ustr, sizeof(ustr), "tcp://%s:%s", ipstr, portstr); - return (nni_getopt_str(ustr, v, szp)); + return (nni_copyout_str(ustr, v, szp, typ)); } static int -nni_tcp_ep_getopt_recvmaxsz(void *arg, void *v, size_t *szp) +nni_tcp_ep_getopt_recvmaxsz(void *arg, void *v, size_t *szp, int typ) { nni_tcp_ep *ep = arg; - return (nni_getopt_size(ep->rcvmax, v, szp)); + return (nni_copyout_size(ep->rcvmax, v, szp, typ)); } static int @@ -769,10 +769,10 @@ nni_tcp_ep_setopt_linger(void *arg, const void *v, size_t sz) } static int -nni_tcp_ep_getopt_linger(void *arg, void *v, size_t *szp) +nni_tcp_ep_getopt_linger(void *arg, void *v, size_t *szp, int typ) { nni_tcp_ep *ep = arg; - return (nni_getopt_ms(ep->linger, v, szp)); + return (nni_copyout_ms(ep->linger, v, szp, typ)); } static nni_tran_pipe_option nni_tcp_pipe_options[] = { diff --git a/src/transport/tls/tls.c b/src/transport/tls/tls.c index 9299ba2d..84125c48 100644 --- a/src/transport/tls/tls.c +++ b/src/transport/tls/tls.c @@ -453,7 +453,7 @@ nni_tls_pipe_peer(void *arg) } static int -nni_tls_pipe_getopt_locaddr(void *arg, void *v, size_t *szp) +nni_tls_pipe_getopt_locaddr(void *arg, void *v, size_t *szp, int typ) { nni_tls_pipe *p = arg; int rv; @@ -461,13 +461,13 @@ nni_tls_pipe_getopt_locaddr(void *arg, void *v, size_t *szp) memset(&sa, 0, sizeof(sa)); if ((rv = nni_tls_sockname(p->tls, &sa)) == 0) { - rv = nni_getopt_sockaddr(&sa, v, szp); + rv = nni_copyout_sockaddr(&sa, v, szp, typ); } return (rv); } static int -nni_tls_pipe_getopt_remaddr(void *arg, void *v, size_t *szp) +nni_tls_pipe_getopt_remaddr(void *arg, void *v, size_t *szp, int typ) { nni_tls_pipe *p = arg; int rv; @@ -475,7 +475,7 @@ nni_tls_pipe_getopt_remaddr(void *arg, void *v, size_t *szp) memset(&sa, 0, sizeof(sa)); if ((rv = nni_tls_peername(p->tls, &sa)) == 0) { - rv = nni_getopt_sockaddr(&sa, v, szp); + rv = nni_copyout_sockaddr(&sa, v, szp, typ); } return (rv); } @@ -749,7 +749,7 @@ nni_tls_ep_connect(void *arg, nni_aio *aio) } static int -nni_tls_ep_getopt_url(void *arg, void *v, size_t *szp) +nni_tls_ep_getopt_url(void *arg, void *v, size_t *szp, int typ) { nni_tls_ep *ep = arg; char ustr[128]; @@ -757,11 +757,11 @@ nni_tls_ep_getopt_url(void *arg, void *v, size_t *szp) char portstr[6]; // max for 16-bit port if (ep->mode == NNI_EP_MODE_DIAL) { - return (nni_getopt_str(ep->url->u_rawurl, v, szp)); + return (nni_copyout_str(ep->url->u_rawurl, v, szp, typ)); } nni_plat_tcp_ntop(&ep->bsa, ipstr, portstr); snprintf(ustr, sizeof(ustr), "tls+tcp://%s:%s", ipstr, portstr); - return (nni_getopt_str(ustr, v, szp)); + return (nni_copyout_str(ustr, v, szp, typ)); } static int @@ -775,10 +775,10 @@ nni_tls_ep_setopt_recvmaxsz(void *arg, const void *v, size_t sz) } static int -nni_tls_ep_getopt_recvmaxsz(void *arg, void *v, size_t *szp) +nni_tls_ep_getopt_recvmaxsz(void *arg, void *v, size_t *szp, int typ) { nni_tls_ep *ep = arg; - return (nni_getopt_size(ep->rcvmax, v, szp)); + return (nni_copyout_size(ep->rcvmax, v, szp, typ)); } static int @@ -792,10 +792,10 @@ nni_tls_ep_setopt_linger(void *arg, const void *v, size_t sz) } static int -nni_tls_ep_getopt_linger(void *arg, void *v, size_t *szp) +nni_tls_ep_getopt_linger(void *arg, void *v, size_t *szp, int typ) { nni_tls_ep *ep = arg; - return (nni_getopt_ms(ep->linger, v, szp)); + return (nni_copyout_ms(ep->linger, v, szp, typ)); } static int @@ -824,10 +824,10 @@ tls_setopt_config(void *arg, const void *data, size_t sz) } static int -tls_getopt_config(void *arg, void *v, size_t *szp) +tls_getopt_config(void *arg, void *v, size_t *szp, int typ) { nni_tls_ep *ep = arg; - return (nni_getopt_ptr(ep->cfg, v, szp)); + return (nni_copyout_ptr(ep->cfg, v, szp, typ)); } static int @@ -888,11 +888,11 @@ tls_setopt_cert_key_file(void *arg, const void *v, size_t sz) } static int -tls_getopt_verified(void *arg, void *v, size_t *szp) +tls_getopt_verified(void *arg, void *v, size_t *szp, int typ) { nni_tls_pipe *p = arg; - return (nni_getopt_bool(nni_tls_verified(p->tls), v, szp)); + return (nni_copyout_bool(nni_tls_verified(p->tls), v, szp, typ)); } static nni_tran_pipe_option nni_tls_pipe_options[] = { diff --git a/src/transport/ws/websocket.c b/src/transport/ws/websocket.c index 1b862d73..1a83462a 100644 --- a/src/transport/ws/websocket.c +++ b/src/transport/ws/websocket.c @@ -470,14 +470,14 @@ ws_ep_setopt_reshdrs(void *arg, const void *v, size_t sz) } static int -ws_ep_getopt_recvmaxsz(void *arg, void *v, size_t *szp) +ws_ep_getopt_recvmaxsz(void *arg, void *v, size_t *szp, int typ) { ws_ep *ep = arg; - return (nni_getopt_size(ep->rcvmax, v, szp)); + return (nni_copyout_size(ep->rcvmax, v, szp, typ)); } static int -ws_pipe_getopt_locaddr(void *arg, void *v, size_t *szp) +ws_pipe_getopt_locaddr(void *arg, void *v, size_t *szp, int typ) { ws_pipe * p = arg; int rv; @@ -485,13 +485,13 @@ ws_pipe_getopt_locaddr(void *arg, void *v, size_t *szp) memset(&sa, 0, sizeof(sa)); if ((rv = nni_ws_sock_addr(p->ws, &sa)) == 0) { - rv = nni_getopt_sockaddr(&sa, v, szp); + rv = nni_copyout_sockaddr(&sa, v, szp, typ); } return (rv); } static int -ws_pipe_getopt_remaddr(void *arg, void *v, size_t *szp) +ws_pipe_getopt_remaddr(void *arg, void *v, size_t *szp, int typ) { ws_pipe * p = arg; int rv; @@ -499,13 +499,13 @@ ws_pipe_getopt_remaddr(void *arg, void *v, size_t *szp) memset(&sa, 0, sizeof(sa)); if ((rv = nni_ws_peer_addr(p->ws, &sa)) == 0) { - rv = nni_getopt_sockaddr(&sa, v, szp); + rv = nni_copyout_sockaddr(&sa, v, szp, typ); } return (rv); } static int -ws_pipe_getopt_reshdrs(void *arg, void *v, size_t *szp) +ws_pipe_getopt_reshdrs(void *arg, void *v, size_t *szp, int typ) { ws_pipe * p = arg; const char *s; @@ -513,11 +513,11 @@ ws_pipe_getopt_reshdrs(void *arg, void *v, size_t *szp) if ((s = nni_ws_response_headers(p->ws)) == NULL) { return (NNG_ENOMEM); } - return (nni_getopt_str(s, v, szp)); + return (nni_copyout_str(s, v, szp, typ)); } static int -ws_pipe_getopt_reqhdrs(void *arg, void *v, size_t *szp) +ws_pipe_getopt_reqhdrs(void *arg, void *v, size_t *szp, int typ) { ws_pipe * p = arg; const char *s; @@ -525,14 +525,14 @@ ws_pipe_getopt_reqhdrs(void *arg, void *v, size_t *szp) if ((s = nni_ws_request_headers(p->ws)) == NULL) { return (NNG_ENOMEM); } - return (nni_getopt_str(s, v, szp)); + return (nni_copyout_str(s, v, szp, typ)); } static int -ws_pipe_getopt_tls_verified(void *arg, void *v, size_t *szp) +ws_pipe_getopt_tls_verified(void *arg, void *v, size_t *szp, int typ) { ws_pipe *p = arg; - return (nni_getopt_bool(nni_ws_tls_verified(p->ws), v, szp)); + return (nni_copyout_bool(nni_ws_tls_verified(p->ws), v, szp, typ)); } static nni_tran_pipe_option ws_pipe_options[] = { @@ -815,14 +815,14 @@ wss_get_tls(ws_ep *ep, nng_tls_config **tlsp) } static int -wss_ep_getopt_tlsconfig(void *arg, void *v, size_t *szp) +wss_ep_getopt_tlsconfig(void *arg, void *v, size_t *szp, int typ) { ws_ep * ep = arg; nng_tls_config *tls; int rv; if (((rv = wss_get_tls(ep, &tls)) != 0) || - ((rv = nni_getopt_ptr(tls, v, szp)) != 0)) { + ((rv = nni_copyout_ptr(tls, v, szp, typ)) != 0)) { return (rv); } return (0); diff --git a/src/transport/zerotier/zerotier.c b/src/transport/zerotier/zerotier.c index 98dbe2bd..da22dc54 100644 --- a/src/transport/zerotier/zerotier.c +++ b/src/transport/zerotier/zerotier.c @@ -1927,7 +1927,8 @@ zt_pipe_peer(void *arg) } static int -zt_getopt_network_status(zt_node *ztn, uint64_t nwid, void *buf, size_t *szp) +zt_getopt_nw_status( + zt_node *ztn, uint64_t nwid, void *buf, size_t *szp, int typ) { ZT_VirtualNetworkConfig *vcfg; int status; @@ -1964,11 +1965,11 @@ zt_getopt_network_status(zt_node *ztn, uint64_t nwid, void *buf, size_t *szp) ZT_Node_freeQueryResult(ztn->zn_znode, vcfg); nni_mtx_unlock(&zt_lk); - return (nni_getopt_int(status, buf, szp)); + return (nni_copyout_int(status, buf, szp, typ)); } static int -zt_getopt_network_name(zt_node *ztn, uint64_t nwid, void *buf, size_t *szp) +zt_getopt_nw_name(zt_node *ztn, uint64_t nwid, void *buf, size_t *szp, int typ) { ZT_VirtualNetworkConfig *vcfg; int rv; @@ -1979,7 +1980,8 @@ zt_getopt_network_name(zt_node *ztn, uint64_t nwid, void *buf, size_t *szp) nni_mtx_unlock(&zt_lk); return (NNG_ECLOSED); } - rv = nni_getopt_str(vcfg->name, buf, szp); + + rv = nni_copyout_str(vcfg->name, buf, szp, typ); ZT_Node_freeQueryResult(ztn->zn_znode, vcfg); nni_mtx_unlock(&zt_lk); @@ -1987,24 +1989,24 @@ zt_getopt_network_name(zt_node *ztn, uint64_t nwid, void *buf, size_t *szp) } static int -zt_pipe_get_recvmaxsz(void *arg, void *buf, size_t *szp) +zt_pipe_get_recvmaxsz(void *arg, void *buf, size_t *szp, int typ) { zt_pipe *p = arg; - return (nni_getopt_size(p->zp_rcvmax, buf, szp)); + return (nni_copyout_size(p->zp_rcvmax, buf, szp, typ)); } static int -zt_pipe_get_nwid(void *arg, void *buf, size_t *szp) +zt_pipe_get_nwid(void *arg, void *buf, size_t *szp, int typ) { zt_pipe *p = arg; - return (nni_getopt_u64(p->zp_nwid, buf, szp)); + return (nni_copyout_u64(p->zp_nwid, buf, szp, typ)); } static int -zt_pipe_get_node(void *arg, void *buf, size_t *szp) +zt_pipe_get_node(void *arg, void *buf, size_t *szp, int typ) { zt_pipe *p = arg; - return (nni_getopt_u64(p->zp_laddr >> 24, buf, szp)); + return (nni_copyout_u64(p->zp_laddr >> 24, buf, szp, typ)); } static void @@ -2545,10 +2547,10 @@ zt_ep_setopt_recvmaxsz(void *arg, const void *data, size_t sz) } static int -zt_ep_getopt_recvmaxsz(void *arg, void *data, size_t *szp) +zt_ep_getopt_recvmaxsz(void *arg, void *data, size_t *szp, int typ) { zt_ep *ep = arg; - return (nni_getopt_size(ep->ze_rcvmax, data, szp)); + return (nni_copyout_size(ep->ze_rcvmax, data, szp, typ)); } static int @@ -2579,14 +2581,14 @@ zt_ep_setopt_home(void *arg, const void *data, size_t sz) } static int -zt_ep_getopt_home(void *arg, void *data, size_t *szp) +zt_ep_getopt_home(void *arg, void *data, size_t *szp, int typ) { zt_ep *ep = arg; - return (nni_getopt_str(ep->ze_home, data, szp)); + return (nni_copyout_str(ep->ze_home, data, szp, typ)); } static int -zt_ep_getopt_url(void *arg, void *data, size_t *szp) +zt_ep_getopt_url(void *arg, void *data, size_t *szp, int typ) { char ustr[64]; // more than plenty zt_ep * ep = arg; @@ -2597,7 +2599,7 @@ zt_ep_getopt_url(void *arg, void *data, size_t *szp) (unsigned long long) addr >> zt_port_shift, (unsigned long long) ep->ze_nwid, (unsigned) (addr & zt_port_mask)); - return (nni_getopt_str(ustr, data, szp)); + return (nni_copyout_str(ustr, data, szp, typ)); } static int @@ -2645,31 +2647,31 @@ zt_ep_setopt_deorbit(void *arg, const void *data, size_t sz) } static int -zt_ep_getopt_node(void *arg, void *data, size_t *szp) +zt_ep_getopt_node(void *arg, void *data, size_t *szp, int typ) { zt_ep *ep = arg; - return (nni_getopt_u64(ep->ze_ztn->zn_self, data, szp)); + return (nni_copyout_u64(ep->ze_ztn->zn_self, data, szp, typ)); } static int -zt_ep_getopt_nwid(void *arg, void *data, size_t *szp) +zt_ep_getopt_nwid(void *arg, void *data, size_t *szp, int typ) { zt_ep *ep = arg; - return (nni_getopt_u64(ep->ze_nwid, data, szp)); + return (nni_copyout_u64(ep->ze_nwid, data, szp, typ)); } static int -zt_ep_getopt_network_name(void *arg, void *buf, size_t *szp) +zt_ep_getopt_nw_name(void *arg, void *buf, size_t *szp, int typ) { zt_ep *ep = arg; - return (zt_getopt_network_name(ep->ze_ztn, ep->ze_nwid, buf, szp)); + return (zt_getopt_nw_name(ep->ze_ztn, ep->ze_nwid, buf, szp, typ)); } static int -zt_ep_getopt_network_status(void *arg, void *buf, size_t *szp) +zt_ep_getopt_nw_status(void *arg, void *buf, size_t *szp, int typ) { zt_ep *ep = arg; - return (zt_getopt_network_status(ep->ze_ztn, ep->ze_nwid, buf, szp)); + return (zt_getopt_nw_status(ep->ze_ztn, ep->ze_nwid, buf, szp, typ)); } static int @@ -2683,10 +2685,10 @@ zt_ep_setopt_ping_time(void *arg, const void *data, size_t sz) } static int -zt_ep_getopt_ping_time(void *arg, void *data, size_t *szp) +zt_ep_getopt_ping_time(void *arg, void *data, size_t *szp, int typ) { zt_ep *ep = arg; - return (nni_getopt_ms(ep->ze_ping_time, data, szp)); + return (nni_copyout_ms(ep->ze_ping_time, data, szp, typ)); } static int @@ -2700,10 +2702,10 @@ zt_ep_setopt_ping_tries(void *arg, const void *data, size_t sz) } static int -zt_ep_getopt_ping_tries(void *arg, void *data, size_t *szp) +zt_ep_getopt_ping_tries(void *arg, void *data, size_t *szp, int typ) { zt_ep *ep = arg; - return (nni_getopt_int(ep->ze_ping_tries, data, szp)); + return (nni_copyout_int(ep->ze_ping_tries, data, szp, typ)); } static int @@ -2717,10 +2719,10 @@ zt_ep_setopt_conn_time(void *arg, const void *data, size_t sz) } static int -zt_ep_getopt_conn_time(void *arg, void *data, size_t *szp) +zt_ep_getopt_conn_time(void *arg, void *data, size_t *szp, int typ) { zt_ep *ep = arg; - return (nni_getopt_ms(ep->ze_conn_time, data, szp)); + return (nni_copyout_ms(ep->ze_conn_time, data, szp, typ)); } static int @@ -2734,14 +2736,14 @@ zt_ep_setopt_conn_tries(void *arg, const void *data, size_t sz) } static int -zt_ep_getopt_conn_tries(void *arg, void *data, size_t *szp) +zt_ep_getopt_conn_tries(void *arg, void *data, size_t *szp, int typ) { zt_ep *ep = arg; - return (nni_getopt_int(ep->ze_conn_tries, data, szp)); + return (nni_copyout_int(ep->ze_conn_tries, data, szp, typ)); } static int -zt_pipe_getopt_locaddr(void *arg, void *data, size_t *szp) +zt_pipe_getopt_locaddr(void *arg, void *data, size_t *szp, int typ) { zt_pipe * p = arg; nng_sockaddr sa; @@ -2751,11 +2753,11 @@ zt_pipe_getopt_locaddr(void *arg, void *data, size_t *szp) sa.s_zt.sa_nwid = p->zp_nwid; sa.s_zt.sa_nodeid = p->zp_laddr >> zt_port_shift; sa.s_zt.sa_port = p->zp_laddr & zt_port_mask; - return (nni_getopt_sockaddr(&sa, data, szp)); + return (nni_copyout_sockaddr(&sa, data, szp, typ)); } static int -zt_pipe_getopt_remaddr(void *arg, void *data, size_t *szp) +zt_pipe_getopt_remaddr(void *arg, void *data, size_t *szp, int typ) { zt_pipe * p = arg; nng_sockaddr sa; @@ -2765,14 +2767,14 @@ zt_pipe_getopt_remaddr(void *arg, void *data, size_t *szp) sa.s_zt.sa_nwid = p->zp_nwid; sa.s_zt.sa_nodeid = p->zp_raddr >> zt_port_shift; sa.s_zt.sa_port = p->zp_raddr & zt_port_mask; - return (nni_getopt_sockaddr(&sa, data, szp)); + return (nni_copyout_sockaddr(&sa, data, szp, typ)); } static int -zt_pipe_getopt_mtu(void *arg, void *data, size_t *szp) +zt_pipe_getopt_mtu(void *arg, void *data, size_t *szp, int typ) { zt_pipe *p = arg; - return (nni_getopt_size(p->zp_mtu, data, szp)); + return (nni_copyout_size(p->zp_mtu, data, szp, typ)); } static nni_tran_pipe_option zt_pipe_options[] = { @@ -2856,13 +2858,13 @@ static nni_tran_ep_option zt_ep_options[] = { { .eo_name = NNG_OPT_ZT_NETWORK_STATUS, .eo_type = NNI_TYPE_INT32, // enumeration really - .eo_getopt = zt_ep_getopt_network_status, + .eo_getopt = zt_ep_getopt_nw_status, .eo_setopt = NULL, }, { .eo_name = NNG_OPT_ZT_NETWORK_NAME, .eo_type = NNI_TYPE_STRING, - .eo_getopt = zt_ep_getopt_network_name, + .eo_getopt = zt_ep_getopt_nw_name, .eo_setopt = NULL, }, { |
