aboutsummaryrefslogtreecommitdiff
path: root/src/core/options.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/options.c')
-rw-r--r--src/core/options.c127
1 files changed, 0 insertions, 127 deletions
diff --git a/src/core/options.c b/src/core/options.c
index e9a79f35..d08ac1cb 100644
--- a/src/core/options.c
+++ b/src/core/options.c
@@ -13,19 +13,6 @@
#include <stdio.h>
#include <string.h>
-// Dynamic options.
-
-typedef struct nni_option nni_option;
-struct nni_option {
- nni_list_node o_link;
- char * o_name;
- int o_id;
-};
-
-static nni_mtx nni_option_lk;
-static nni_list nni_options;
-static int nni_option_nextid;
-
int
nni_chkopt_usec(const void *v, size_t sz)
{
@@ -293,117 +280,3 @@ nni_getopt_fd(nni_sock *s, nni_notifyfd *fd, int mask, void *val, size_t *szp)
memcpy(val, &fd->sn_rfd, sizeof(int));
return (0);
}
-
-// nni_option_set_id sets the id for an option, if not already done so.
-// (Some options have hard coded values that end-user may depend upon.)
-// If the ID passed in is negative, then a new ID is allocated dynamically.
-static int
-nni_option_set_id(const char *name, int id)
-{
- nni_option *opt;
- size_t len;
- nni_mtx_lock(&nni_option_lk);
- NNI_LIST_FOREACH (&nni_options, opt) {
- if (strcmp(name, opt->o_name) == 0) {
- nni_mtx_unlock(&nni_option_lk);
- return (0);
- }
- }
- if ((opt = NNI_ALLOC_STRUCT(opt)) == NULL) {
- nni_mtx_unlock(&nni_option_lk);
- return (NNG_ENOMEM);
- }
- if ((opt->o_name = nni_strdup(name)) == NULL) {
- nni_mtx_unlock(&nni_option_lk);
- NNI_FREE_STRUCT(opt);
- return (NNG_ENOMEM);
- }
- if (id < 0) {
- id = nni_option_nextid++;
- }
- opt->o_id = id;
- nni_list_append(&nni_options, opt);
- nni_mtx_unlock(&nni_option_lk);
- return (0);
-}
-
-int
-nni_option_lookup(const char *name)
-{
- nni_option *opt;
- int id = -1;
-
- nni_mtx_lock(&nni_option_lk);
- NNI_LIST_FOREACH (&nni_options, opt) {
- if (strcmp(name, opt->o_name) == 0) {
- id = opt->o_id;
- break;
- }
- }
- nni_mtx_unlock(&nni_option_lk);
- return (id);
-}
-
-int
-nni_option_register(const char *name, int *idp)
-{
- int rv;
-
- // Note that if the id was already in use, we will
- // wind up leaving a gap in the ID space. That should
- // be inconsequential.
- if ((rv = nni_option_set_id(name, -1)) != 0) {
- return (rv);
- }
- *idp = nni_option_lookup(name);
- return (0);
-}
-
-void
-nni_option_sys_fini(void)
-{
- if (nni_option_nextid != 0) {
- nni_option *opt;
- while ((opt = nni_list_first(&nni_options)) != NULL) {
- nni_list_remove(&nni_options, opt);
- nni_strfree(opt->o_name);
- NNI_FREE_STRUCT(opt);
- }
- }
- 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)
-{
- nni_mtx_init(&nni_option_lk);
- NNI_LIST_INIT(&nni_options, nni_option, o_link);
- nni_option_nextid = 0x10000;
- int rv;
-
-#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(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(surveyor_surveytime)) != 0)) {
- nni_option_sys_fini();
- return (rv);
- }
-#undef OPT_REGISTER
-
- return (0);
-}