diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-09-27 15:14:14 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-09-27 15:14:14 -0700 |
| commit | 0736a958673683a9bfe0bf577b696f49c7bd8302 (patch) | |
| tree | 93f1995f7e7130ffe31cc9701be6b390faabd6e7 /src/core | |
| parent | 64db0f085be0c9efc6dca8d9e72d3e5a47cb792e (diff) | |
| download | nng-0736a958673683a9bfe0bf577b696f49c7bd8302.tar.gz nng-0736a958673683a9bfe0bf577b696f49c7bd8302.tar.bz2 nng-0736a958673683a9bfe0bf577b696f49c7bd8302.zip | |
Remove last vestiges of integer option numbers.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/init.c | 2 | ||||
| -rw-r--r-- | src/core/options.c | 127 | ||||
| -rw-r--r-- | src/core/options.h | 17 | ||||
| -rw-r--r-- | src/core/socket.c | 3 |
4 files changed, 0 insertions, 149 deletions
diff --git a/src/core/init.c b/src/core/init.c index 36f96d61..cb242338 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -21,7 +21,6 @@ nni_init_helper(void) ((rv = nni_timer_sys_init()) != 0) || ((rv = nni_aio_sys_init()) != 0) || ((rv = nni_random_sys_init()) != 0) || - ((rv = nni_option_sys_init()) != 0) || ((rv = nni_sock_sys_init()) != 0) || ((rv = nni_ep_sys_init()) != 0) || ((rv = nni_pipe_sys_init()) != 0) || @@ -46,7 +45,6 @@ nni_fini(void) nni_pipe_sys_fini(); nni_ep_sys_fini(); nni_sock_sys_fini(); - nni_option_sys_fini(); nni_random_sys_fini(); nni_aio_sys_fini(); nni_timer_sys_fini(); 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); -} diff --git a/src/core/options.h b/src/core/options.h index 418a5d00..cf2176b8 100644 --- a/src/core/options.h +++ b/src/core/options.h @@ -65,21 +65,4 @@ extern int nni_chkopt_usec(const void *, size_t); extern int nni_chkopt_int(const void *, size_t, int, int); extern int nni_chkopt_size(const void *, size_t, size_t, size_t); -extern int nni_option_register(const char *, int *); -extern int nni_option_lookup(const char *); -extern const char *nni_option_name(int); - -extern int nni_option_sys_init(void); -extern void nni_option_sys_fini(void); - -extern int nni_optid_raw; -extern int nni_optid_recvmaxsz; -extern int nni_optid_maxttl; -extern int nni_optid_protocol; -extern int nni_optid_transport; -extern int nni_optid_locaddr; -extern int nni_optid_remaddr; -extern int nni_optid_req_resendtime; -extern int nni_optid_surveyor_surveytime; - #endif // CORE_OPTIONS_H diff --git a/src/core/socket.c b/src/core/socket.c index dc305b48..e1cb1294 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1095,12 +1095,9 @@ nni_sock_getopt(nni_sock *s, const char *name, void *val, size_t *szp) { int rv = NNG_ENOTSUP; nni_sockopt * sopt; - int opt; const nni_socket_option * sso; const nni_proto_sock_option *pso; - opt = nni_option_lookup(name); - nni_mtx_lock(&s->s_mx); if (s->s_closing) { nni_mtx_unlock(&s->s_mx); |
