From 0736a958673683a9bfe0bf577b696f49c7bd8302 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 27 Sep 2017 15:14:14 -0700 Subject: Remove last vestiges of integer option numbers. --- src/core/init.c | 2 - src/core/options.c | 127 -------------------------------------- src/core/options.h | 17 ----- src/core/socket.c | 3 - src/nng.c | 13 ---- src/nng.h | 11 +--- src/nng_compat.c | 2 +- src/protocol/pair/pair_v1.c | 8 +-- src/transport/zerotier/zerotier.c | 34 +--------- 9 files changed, 6 insertions(+), 211 deletions(-) (limited to 'src') 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 #include -// 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); diff --git a/src/nng.c b/src/nng.c index d30a8442..7a78357e 100644 --- a/src/nng.c +++ b/src/nng.c @@ -1013,16 +1013,3 @@ nng_thread_destroy(void *arg) NNI_FREE_STRUCT(thr); } - -// Constant option definitions. These are for well-known options, -// so that the vast majority of consumers don't have to look these up. - -const char *nng_opt_raw = "raw"; -const char *nng_opt_recvmaxsz = "recv-size-max"; -const char *nng_opt_maxttl = "ttl-max"; -const char *nng_opt_protocol = "protocol"; -const char *nng_opt_transport = "transport"; -const char *nng_opt_locaddr = "local-address"; -const char *nng_opt_remaddr = "remote-address"; -// Well known protocol options. -const char *nng_opt_surveyor_surveytime = "surveyor:survey-time"; diff --git a/src/nng.h b/src/nng.h index c0f26063..59bcf8c6 100644 --- a/src/nng.h +++ b/src/nng.h @@ -415,6 +415,8 @@ NNG_DECL int nng_respondent0_open(nng_socket *); #define NNG_OPT_RECONNMINT "reconnect-time-min" #define NNG_OPT_RECONNMAXT "reconnect-time-max" +#define NNG_OPT_PAIR1_POLY "pair1:polyamorous" + #define NNG_OPT_SUB_SUBSCRIBE "sub:subscribe" #define NNG_OPT_SUB_UNSUBSCRIBE "sub:unsubscribe" @@ -422,15 +424,6 @@ NNG_DECL int nng_respondent0_open(nng_socket *); #define NNG_OPT_SURVEYOR_SURVEYTIME "surveyor:survey-time" -NNG_DECL const char *nng_opt_raw; -NNG_DECL const char *nng_opt_recvmaxsz; -NNG_DECL const char *nng_opt_maxttl; -NNG_DECL const char *nng_opt_protocol; -NNG_DECL const char *nng_opt_transport; -NNG_DECL const char *nng_opt_locaddr; -NNG_DECL const char *nng_opt_remaddr; -NNG_DECL const char *nng_opt_surveyor_surveytime; - // XXX: TBD: priorities, socket names, ipv4only // Statistics. These are for informational purposes only, and subject diff --git a/src/nng_compat.c b/src/nng_compat.c index bceabe61..994c1332 100644 --- a/src/nng_compat.c +++ b/src/nng_compat.c @@ -663,7 +663,7 @@ init_opts(void) case NN_SURVEYOR: switch (options[i].nnopt) { case NN_SURVEYOR_DEADLINE: - SETOPT(nng_opt_surveyor_surveytime, 1); + SETOPT(NNG_OPT_SURVEYOR_SURVEYTIME, 1); break; } break; diff --git a/src/protocol/pair/pair_v1.c b/src/protocol/pair/pair_v1.c index 2cd5782b..0b9e0643 100644 --- a/src/protocol/pair/pair_v1.c +++ b/src/protocol/pair/pair_v1.c @@ -25,10 +25,6 @@ static void pair1_pipe_getq_cb(void *); static void pair1_pipe_putq_cb(void *); static void pair1_pipe_fini(void *); -// This is exposed as an external name for external consumers. -#define NNG_OPT_PAIR1_POLY "pair1-polyamorous" -const char *nng_opt_pair1_poly = NNG_OPT_PAIR1_POLY; - // pair1_sock is our per-socket protocol private structure. struct pair1_sock { nni_sock * nsock; @@ -73,7 +69,6 @@ pair1_sock_init(void **sp, nni_sock *nsock) { pair1_sock *s; int rv; - int poly; if ((s = NNI_ALLOC_STRUCT(s)) == NULL) { return (NNG_ENOMEM); @@ -87,8 +82,7 @@ pair1_sock_init(void **sp, nni_sock *nsock) // Raw mode uses this. nni_mtx_init(&s->mtx); - if (((rv = nni_aio_init(&s->aio_getq, pair1_sock_getq_cb, s)) != 0) || - ((rv = nni_option_register("polyamorous", &poly)) != 0)) { + if ((rv = nni_aio_init(&s->aio_getq, pair1_sock_getq_cb, s)) != 0) { pair1_sock_fini(s); return (rv); } diff --git a/src/transport/zerotier/zerotier.c b/src/transport/zerotier/zerotier.c index 9182ec1f..743e5133 100644 --- a/src/transport/zerotier/zerotier.c +++ b/src/transport/zerotier/zerotier.c @@ -38,16 +38,8 @@ const char *nng_opt_zt_network_name = NNG_ZT_OPT_NETWORK_NAME; const char *nng_opt_zt_ping_time = NNG_ZT_OPT_PING_TIME; const char *nng_opt_zt_ping_count = NNG_ZT_OPT_PING_COUNT; -int zt_optid_home = -1; -int zt_optid_nwid = -1; -int zt_optid_node = -1; -int zt_optid_status = -1; -int zt_optid_network_name = -1; -int zt_optid_ping_time = -1; -int zt_optid_ping_count = -1; - // These values are supplied to help folks checking status. They are the -// return values from zt_optid_status. +// return values from zt_opt_status. int nng_zt_status_configuring = ZT_NETWORK_STATUS_REQUESTING_CONFIGURATION; int nng_zt_status_ok = ZT_NETWORK_STATUS_OK; int nng_zt_status_denied = ZT_NETWORK_STATUS_ACCESS_DENIED; @@ -1605,23 +1597,6 @@ done: static int zt_tran_init(void) { - int rv; - if (((rv = nni_option_register(nng_opt_zt_home, &zt_optid_home)) != - 0) || - ((rv = nni_option_register(nng_opt_zt_node, &zt_optid_node)) != - 0) || - ((rv = nni_option_register(nng_opt_zt_nwid, &zt_optid_nwid)) != - 0) || - ((rv = nni_option_register(nng_opt_zt_status, &zt_optid_status)) != - 0) || - ((rv = nni_option_register( - nng_opt_zt_network_name, &zt_optid_network_name)) != 0) || - ((rv = nni_option_register( - nng_opt_zt_ping_count, &zt_optid_ping_count)) != 0) || - ((rv = nni_option_register( - nng_opt_zt_ping_time, &zt_optid_ping_time)) != 0)) { - return (rv); - } nni_mtx_init(&zt_lk); NNI_LIST_INIT(&zt_nodes, zt_node, zn_link); return (0); @@ -1630,11 +1605,6 @@ zt_tran_init(void) static void zt_tran_fini(void) { - zt_optid_home = -1; - zt_optid_nwid = -1; - zt_optid_node = -1; - zt_optid_ping_count = -1; - zt_optid_ping_time = -1; zt_node *ztn; nni_mtx_lock(&zt_lk); @@ -2494,7 +2464,7 @@ zt_ep_conn_req_cb(void *arg) static void zt_ep_connect(void *arg, nni_aio *aio) { - zt_ep * ep = arg; + zt_ep *ep = arg; // We bind locally. We'll use the address later when we give // it to the pipe, but this allows us to receive the initial -- cgit v1.2.3-70-g09d2