diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-09-25 12:49:10 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-09-27 14:38:12 -0700 |
| commit | 64db0f085be0c9efc6dca8d9e72d3e5a47cb792e (patch) | |
| tree | 475520498d8ebe9e47e9785d8f9d209c87582400 /src/core/transport.c | |
| parent | 86a96e5bf1b207a8b1aa925e1d9f73ce834505b8 (diff) | |
| download | nng-64db0f085be0c9efc6dca8d9e72d3e5a47cb792e.tar.gz nng-64db0f085be0c9efc6dca8d9e72d3e5a47cb792e.tar.bz2 nng-64db0f085be0c9efc6dca8d9e72d3e5a47cb792e.zip | |
Refactor option handling APIs.
This makes the APIs use string keys, and largely eliminates the use of
integer option IDs altogether. The underlying registration for options
is also now a bit richer, letting protcols and transports declare the
actual options they use, rather than calling down into each entry point
carte blanche and relying on ENOTSUP.
This code may not be as fast as the integers was, but it is more intuitive,
easier to extend, and is not on any hot code paths. (If you're diddling
options on a hot code path you're doing something wrong.)
Diffstat (limited to 'src/core/transport.c')
| -rw-r--r-- | src/core/transport.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/core/transport.c b/src/core/transport.c index eead861b..2697ce74 100644 --- a/src/core/transport.c +++ b/src/core/transport.c @@ -97,19 +97,29 @@ nni_tran_find(const char *addr) } int -nni_tran_chkopt(int o, const void *v, size_t sz) +nni_tran_chkopt(const char *name, const void *v, size_t sz) { nni_transport *t; int rv = NNG_ENOTSUP; + nni_mtx_lock(&nni_tran_lk); NNI_LIST_FOREACH (&nni_tran_list, t) { - int x; - if (t->t_tran.tran_chkopt == NULL) { - continue; - } - if ((x = t->t_tran.tran_chkopt(o, v, sz)) != NNG_ENOTSUP) { - if ((rv = x) != 0) { - break; + const nni_tran_ep * ep; + const nni_tran_ep_option *eo; + + // Generally we look for endpoint options. + ep = t->t_tran.tran_ep; + for (eo = ep->ep_options; eo && eo->eo_name != NULL; eo++) { + if (strcmp(name, eo->eo_name) != 0) { + continue; + } + if (eo->eo_setopt == NULL) { + nni_mtx_unlock(&nni_tran_lk); + return (NNG_EREADONLY); + } + if ((rv = eo->eo_setopt(NULL, v, sz)) != 0) { + nni_mtx_unlock(&nni_tran_lk); + return (rv); } } } |
