diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-08-24 14:15:48 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-08-24 14:20:34 -0700 |
| commit | c9a68bfe6bea2acc708bf49045f6cb65017a3306 (patch) | |
| tree | e2b93b81b2962bdfb7953cb30fcfae08f0bd4093 /src/core/options.c | |
| parent | 68ff9c823d3cead2b11a003c40c8f5affc11dc71 (diff) | |
| download | nng-c9a68bfe6bea2acc708bf49045f6cb65017a3306.tar.gz nng-c9a68bfe6bea2acc708bf49045f6cb65017a3306.tar.bz2 nng-c9a68bfe6bea2acc708bf49045f6cb65017a3306.zip | |
Eliminate legacy option settings, provide easier option IDs.
This eliminates all the old #define's or enum values, making all
option IDs now totally dynamic, and providing well-known string
values for well-behaved applications.
We have added tests of some of these options, including lookups, and
so forth. We have also fixed a few problems; including at least
one crasher bug when the timeouts on reconnect were zero.
Protocol specific options are now handled in the protocol. We will
be moving the initialization for a few of those well known entities
to the protocol startup code, following the PAIRv1 pattern, later.
Applications must therefore not depend on the value of the integer IDs,
at least until the application has opened a socket of the appropriate
type.
Diffstat (limited to 'src/core/options.c')
| -rw-r--r-- | src/core/options.c | 80 |
1 files changed, 37 insertions, 43 deletions
diff --git a/src/core/options.c b/src/core/options.c index bdbcaaba..7a5de33d 100644 --- a/src/core/options.c +++ b/src/core/options.c @@ -340,6 +340,20 @@ nni_option_register(const char *name, int *idp) 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_free(opt->o_name, strlen(opt->o_name) + 1); + NNI_FREE_STRUCT(opt); + } + } + nni_option_nextid = 0; +} + int nni_option_sys_init(void) { @@ -348,52 +362,32 @@ nni_option_sys_init(void) nni_option_nextid = 0x10000; int rv; +#define OPT_REGISTER(o) nni_option_register(nng_opt_##o, &nng_optid_##o) // Register our well-known options. - if (((rv = nni_option_set_id("raw", NNG_OPT_RAW)) != 0) || - ((rv = nni_option_set_id("linger", NNG_OPT_LINGER)) != 0) || - ((rv = nni_option_set_id("recv-buf", NNG_OPT_RCVBUF)) != 0) || - ((rv = nni_option_set_id("send-buf", NNG_OPT_SNDBUF)) != 0) || - ((rv = nni_option_set_id("recv-timeout", NNG_OPT_RCVTIMEO)) != - 0) || - ((rv = nni_option_set_id("send-timeout", NNG_OPT_SNDTIMEO)) != - 0) || - ((rv = nni_option_set_id("reconnect-time", NNG_OPT_RECONN_TIME)) != - 0) || - ((rv = nni_option_set_id( - "reconnect-max-time", NNG_OPT_RECONN_MAXTIME)) != 0) || - ((rv = nni_option_set_id("recv-max-size", NNG_OPT_RCVMAXSZ)) != - 0) || - ((rv = nni_option_set_id("max-ttl", NNG_OPT_MAXTTL)) != 0) || - ((rv = nni_option_set_id("protocol", NNG_OPT_PROTOCOL)) != 0) || - ((rv = nni_option_set_id("subscribe", NNG_OPT_SUBSCRIBE)) != 0) || - ((rv = nni_option_set_id("unsubscribe", NNG_OPT_UNSUBSCRIBE)) != - 0) || - ((rv = nni_option_set_id("survey-time", NNG_OPT_SURVEYTIME)) != - 0) || - ((rv = nni_option_set_id("resend-time", NNG_OPT_RESENDTIME)) != - 0) || - ((rv = nni_option_set_id("transport", NNG_OPT_TRANSPORT)) != 0) || - ((rv = nni_option_set_id("local-addr", NNG_OPT_LOCALADDR)) != 0) || - ((rv = nni_option_set_id("remote-addr", NNG_OPT_REMOTEADDR)) != - 0) || - ((rv = nni_option_set_id("recv-fd", NNG_OPT_RCVFD)) != 0) || - ((rv = nni_option_set_id("send-fd", NNG_OPT_SNDFD)) != 0)) { + 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(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); } +#undef OPT_REGISTER + 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_free(opt->o_name, strlen(opt->o_name) + 1); - NNI_FREE_STRUCT(opt); - } - } - nni_option_nextid = 0; -}
\ No newline at end of file |
