aboutsummaryrefslogtreecommitdiff
path: root/src/core/options.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-09-25 12:49:10 -0700
committerGarrett D'Amore <garrett@damore.org>2017-09-27 14:38:12 -0700
commit64db0f085be0c9efc6dca8d9e72d3e5a47cb792e (patch)
tree475520498d8ebe9e47e9785d8f9d209c87582400 /src/core/options.c
parent86a96e5bf1b207a8b1aa925e1d9f73ce834505b8 (diff)
downloadnng-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/options.c')
-rw-r--r--src/core/options.c41
1 files changed, 10 insertions, 31 deletions
diff --git a/src/core/options.c b/src/core/options.c
index b7934a06..e9a79f35 100644
--- a/src/core/options.c
+++ b/src/core/options.c
@@ -344,23 +344,6 @@ nni_option_lookup(const char *name)
return (id);
}
-const char *
-nni_option_name(int id)
-{
- nni_option *opt;
- const char *name = NULL;
-
- nni_mtx_lock(&nni_option_lk);
- NNI_LIST_FOREACH (&nni_options, opt) {
- if (id == opt->o_id) {
- name = opt->o_name;
- break;
- }
- }
- nni_mtx_unlock(&nni_option_lk);
- return (name);
-}
-
int
nni_option_register(const char *name, int *idp)
{
@@ -390,6 +373,15 @@ nni_option_sys_fini(void)
nni_option_nextid = 0;
}
+int nni_optid_raw;
+int nni_optid_recvmaxsz;
+int nni_optid_maxttl;
+int nni_optid_protocol;
+int nni_optid_transport;
+int nni_optid_locaddr;
+int nni_optid_remaddr;
+int nni_optid_surveyor_surveytime;
+
int
nni_option_sys_init(void)
{
@@ -398,28 +390,15 @@ nni_option_sys_init(void)
nni_option_nextid = 0x10000;
int rv;
-#define OPT_REGISTER(o) nni_option_register(nng_opt_##o, &nng_optid_##o)
+#define OPT_REGISTER(o) nni_option_register(nng_opt_##o, &nni_optid_##o)
// Register our well-known options.
if (((rv = OPT_REGISTER(raw)) != 0) ||
- ((rv = OPT_REGISTER(linger)) != 0) ||
- ((rv = OPT_REGISTER(recvbuf)) != 0) ||
- ((rv = OPT_REGISTER(sendbuf)) != 0) ||
- ((rv = OPT_REGISTER(recvtimeo)) != 0) ||
- ((rv = OPT_REGISTER(sendtimeo)) != 0) ||
- ((rv = OPT_REGISTER(reconnmint)) != 0) ||
- ((rv = OPT_REGISTER(reconnmaxt)) != 0) ||
((rv = OPT_REGISTER(recvmaxsz)) != 0) ||
((rv = OPT_REGISTER(maxttl)) != 0) ||
((rv = OPT_REGISTER(protocol)) != 0) ||
((rv = OPT_REGISTER(transport)) != 0) ||
((rv = OPT_REGISTER(locaddr)) != 0) ||
((rv = OPT_REGISTER(remaddr)) != 0) ||
- ((rv = OPT_REGISTER(recvfd)) != 0) ||
- ((rv = OPT_REGISTER(sendfd)) != 0) ||
- ((rv = OPT_REGISTER(url)) != 0) ||
- ((rv = OPT_REGISTER(req_resendtime)) != 0) ||
- ((rv = OPT_REGISTER(sub_subscribe)) != 0) ||
- ((rv = OPT_REGISTER(sub_unsubscribe)) != 0) ||
((rv = OPT_REGISTER(surveyor_surveytime)) != 0)) {
nni_option_sys_fini();
return (rv);