aboutsummaryrefslogtreecommitdiff
path: root/src/core/endpt.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-06-12 20:05:34 -0700
committerGarrett D'Amore <garrett@damore.org>2018-06-13 18:01:52 -0700
commitda2aac4a6eb10af88e3938068e24c58aea1832b1 (patch)
treefb0676be5426ed1510945b7e7fe3d09eb45333a7 /src/core/endpt.c
parent61ffae5e3649897776c26799ccaaa35d578ba816 (diff)
downloadnng-da2aac4a6eb10af88e3938068e24c58aea1832b1.tar.gz
nng-da2aac4a6eb10af88e3938068e24c58aea1832b1.tar.bz2
nng-da2aac4a6eb10af88e3938068e24c58aea1832b1.zip
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.
Diffstat (limited to 'src/core/endpt.c')
-rw-r--r--src/core/endpt.c44
1 files changed, 14 insertions, 30 deletions
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);
}