From c9a68bfe6bea2acc708bf49045f6cb65017a3306 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 24 Aug 2017 14:15:48 -0700 Subject: Eliminate legacy option settings, provide easier option IDs. This eliminates all the old #define's or enum values, making all option IDs now totally dynamic, and providing well-known string values for well-behaved applications. We have added tests of some of these options, including lookups, and so forth. We have also fixed a few problems; including at least one crasher bug when the timeouts on reconnect were zero. Protocol specific options are now handled in the protocol. We will be moving the initialization for a few of those well known entities to the protocol startup code, following the PAIRv1 pattern, later. Applications must therefore not depend on the value of the integer IDs, at least until the application has opened a socket of the appropriate type. --- src/transport/inproc/inproc.c | 2 ++ src/transport/ipc/ipc.c | 30 ++++++++++------------------ src/transport/tcp/tcp.c | 46 +++++++++++++++++++------------------------ 3 files changed, 32 insertions(+), 46 deletions(-) (limited to 'src/transport') diff --git a/src/transport/inproc/inproc.c b/src/transport/inproc/inproc.c index 4c79ddfd..23a74998 100644 --- a/src/transport/inproc/inproc.c +++ b/src/transport/inproc/inproc.c @@ -182,6 +182,7 @@ nni_inproc_pipe_getopt(void *arg, int option, void *buf, size_t *szp) nni_inproc_pipe *pipe = arg; size_t len; +#if 0 switch (option) { case NNG_OPT_LOCALADDR: case NNG_OPT_REMOTEADDR: @@ -194,6 +195,7 @@ nni_inproc_pipe_getopt(void *arg, int option, void *buf, size_t *szp) *szp = len; return (0); } +#endif return (NNG_ENOTSUP); } diff --git a/src/transport/ipc/ipc.c b/src/transport/ipc/ipc.c index 4324eedd..e5e19f36 100644 --- a/src/transport/ipc/ipc.c +++ b/src/transport/ipc/ipc.c @@ -64,8 +64,7 @@ static void nni_ipc_ep_cb(void *); static int nni_ipc_tran_chkopt(int o, const void *data, size_t sz) { - switch (o) { - case NNG_OPT_RCVMAXSZ: + if (o == nng_optid_recvmaxsz) { return (nni_chkopt_size(data, sz, 0, NNI_MAXSZ)); } return (NNG_ENOTSUP); @@ -648,37 +647,28 @@ nni_ipc_ep_connect(void *arg, nni_aio *aio) static int nni_ipc_ep_setopt(void *arg, int opt, const void *v, size_t sz) { - int rv; + int rv = NNG_ENOTSUP; nni_ipc_ep *ep = arg; - nni_mtx_lock(&ep->mtx); - switch (opt) { - case NNG_OPT_RCVMAXSZ: + + if (opt == nng_optid_recvmaxsz) { + nni_mtx_lock(&ep->mtx); rv = nni_setopt_size(&ep->rcvmax, v, sz, 0, NNI_MAXSZ); - break; - default: - rv = NNG_ENOTSUP; - break; + nni_mtx_unlock(&ep->mtx); } - nni_mtx_unlock(&ep->mtx); return (rv); } static int nni_ipc_ep_getopt(void *arg, int opt, void *v, size_t *szp) { - int rv; + int rv = NNG_ENOTSUP; nni_ipc_ep *ep = arg; - nni_mtx_lock(&ep->mtx); - switch (opt) { - case NNG_OPT_RCVMAXSZ: + if (opt == nng_optid_recvmaxsz) { + nni_mtx_lock(&ep->mtx); rv = nni_getopt_size(&ep->rcvmax, v, szp); - break; - default: - rv = NNG_ENOTSUP; - break; + nni_mtx_unlock(&ep->mtx); } - nni_mtx_unlock(&ep->mtx); return (rv); } diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c index f5e5ad87..de1bfa66 100644 --- a/src/transport/tcp/tcp.c +++ b/src/transport/tcp/tcp.c @@ -65,10 +65,10 @@ static void nni_tcp_ep_cb(void *arg); static int nni_tcp_tran_chkopt(int o, const void *data, size_t sz) { - switch (o) { - case NNG_OPT_RCVMAXSZ: + if (o == nng_optid_recvmaxsz) { return (nni_chkopt_size(data, sz, 0, NNI_MAXSZ)); - case NNG_OPT_LINGER: + } + if (o == nng_optid_linger) { return (nni_chkopt_usec(data, sz)); } return (NNG_ENOTSUP); @@ -766,45 +766,39 @@ nni_tcp_ep_connect(void *arg, nni_aio *aio) static int nni_tcp_ep_setopt(void *arg, int opt, const void *v, size_t sz) { - int rv; + int rv = NNG_ENOTSUP; nni_tcp_ep *ep = arg; - nni_mtx_lock(&ep->mtx); - switch (opt) { - case NNG_OPT_RCVMAXSZ: + if (opt == nng_optid_recvmaxsz) { + nni_mtx_lock(&ep->mtx); rv = nni_setopt_size(&ep->rcvmax, v, sz, 0, NNI_MAXSZ); - break; - case NNG_OPT_LINGER: + nni_mtx_unlock(&ep->mtx); + + } else if (opt == nng_optid_linger) { + nni_mtx_lock(&ep->mtx); rv = nni_setopt_usec(&ep->linger, v, sz); - break; - default: - rv = NNG_ENOTSUP; - break; + nni_mtx_unlock(&ep->mtx); } - nni_mtx_unlock(&ep->mtx); return (rv); } static int nni_tcp_ep_getopt(void *arg, int opt, void *v, size_t *szp) { - int rv; + int rv = NNG_ENOTSUP; nni_tcp_ep *ep = arg; - nni_mtx_lock(&ep->mtx); - switch (opt) { - case NNG_OPT_RCVMAXSZ: + if (opt == nng_optid_recvmaxsz) { + nni_mtx_lock(&ep->mtx); rv = nni_getopt_size(&ep->rcvmax, v, szp); - break; - case NNG_OPT_LINGER: + nni_mtx_unlock(&ep->mtx); + + } else if (opt == nng_optid_linger) { + nni_mtx_lock(&ep->mtx); rv = nni_getopt_usec(&ep->linger, v, szp); - break; - default: - // XXX: add address properties - rv = NNG_ENOTSUP; - break; + nni_mtx_unlock(&ep->mtx); } - nni_mtx_unlock(&ep->mtx); + // XXX: add address properties return (rv); } -- cgit v1.2.3-70-g09d2