From da2aac4a6eb10af88e3938068e24c58aea1832b1 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 12 Jun 2018 20:05:34 -0700 Subject: fixes #540 nni_ep_opttype serves no purpose fixes #538 setopt should have an explicit chkopt routine fixes #537 Internal TCP API needs better name separation fixes #524 Option types should be "typed" This is a rework of the option management code, to make it both clearer and to prepare for further work to break up endpoints. This reduces a certain amount of dead or redundant code, and actually saves cycles when setting options, as some loops were not terminated that should have been. --- src/core/endpt.c | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) (limited to 'src/core/endpt.c') diff --git a/src/core/endpt.c b/src/core/endpt.c index 9fc26cf3..8e678fb0 100644 --- a/src/core/endpt.c +++ b/src/core/endpt.c @@ -582,26 +582,27 @@ nni_ep_pipe_remove(nni_ep *ep, nni_pipe *pipe) } int -nni_ep_setopt(nni_ep *ep, const char *name, const void *val, size_t sz, int t) +nni_ep_setopt( + nni_ep *ep, const char *name, const void *val, size_t sz, nni_opt_type t) { - nni_tran_ep_option *eo; + nni_tran_option *o; if (strcmp(name, NNG_OPT_URL) == 0) { return (NNG_EREADONLY); } - for (eo = ep->ep_ops.ep_options; eo && eo->eo_name; eo++) { + for (o = ep->ep_ops.ep_options; o && o->o_name; o++) { int rv; - if (strcmp(eo->eo_name, name) != 0) { + if (strcmp(o->o_name, name) != 0) { continue; } - if (eo->eo_setopt == NULL) { + if (o->o_set == NULL) { return (NNG_EREADONLY); } nni_mtx_lock(&ep->ep_mtx); - rv = eo->eo_setopt(ep->ep_data, val, sz, t); + rv = o->o_set(ep->ep_data, val, sz, t); nni_mtx_unlock(&ep->ep_mtx); return (rv); } @@ -616,38 +617,21 @@ nni_ep_mode(nni_ep *ep) } int -nni_ep_opttype(nni_ep *ep, const char *name, int *tp) +nni_ep_getopt( + nni_ep *ep, const char *name, void *valp, size_t *szp, nni_opt_type t) { - nni_tran_ep_option *eo; + nni_tran_option *o; - for (eo = ep->ep_ops.ep_options; eo && eo->eo_name; eo++) { - if (strcmp(eo->eo_name, name) == 0) { - *tp = eo->eo_type; - return (0); - } - } - if (strcmp(name, NNG_OPT_URL) == 0) { - *tp = NNI_TYPE_STRING; - return (0); - } - return (NNG_ENOTSUP); -} - -int -nni_ep_getopt(nni_ep *ep, const char *name, void *valp, size_t *szp, int t) -{ - nni_tran_ep_option *eo; - - for (eo = ep->ep_ops.ep_options; eo && eo->eo_name; eo++) { + for (o = ep->ep_ops.ep_options; o && o->o_name; o++) { int rv; - if (strcmp(eo->eo_name, name) != 0) { + if (strcmp(o->o_name, name) != 0) { continue; } - if (eo->eo_getopt == NULL) { + if (o->o_get == NULL) { return (NNG_EWRITEONLY); } nni_mtx_lock(&ep->ep_mtx); - rv = eo->eo_getopt(ep->ep_data, valp, szp, t); + rv = o->o_get(ep->ep_data, valp, szp, t); nni_mtx_unlock(&ep->ep_mtx); return (rv); } -- cgit v1.2.3-70-g09d2