From 5b35daaf2fe6c6fbe0b15740efbffe16ff278e6c Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 29 Dec 2018 16:16:57 -0800 Subject: IPC option rework (pipe/conn) to reduce code duplication. --- src/core/options.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/core/options.c') diff --git a/src/core/options.c b/src/core/options.c index d61b35ac..097b92b2 100644 --- a/src/core/options.c +++ b/src/core/options.c @@ -366,3 +366,35 @@ nni_copyout_str(const char *str, void *dst, size_t *szp, nni_opt_type t) return (NNG_EBADTYPE); } } + +int +nni_getopt(const nni_option *opts, const char *nm, void *arg, void *buf, + size_t *szp, nni_opt_type otype) +{ + while (opts->o_name != NULL) { + if (strcmp(opts->o_name, nm) == 0) { + if (opts->o_get == NULL) { + return (NNG_EWRITEONLY); + } + return (opts->o_get(arg, buf, szp, otype)); + } + opts++; + } + return (NNG_ENOTSUP); +} + +int +nni_setopt(const nni_option *opts, const char *nm, void *arg, const void *buf, + size_t sz, nni_opt_type otype) +{ + while (opts->o_name != NULL) { + if (strcmp(opts->o_name, nm) == 0) { + if (opts->o_set == NULL) { + return (NNG_EREADONLY); + } + return (opts->o_set(arg, buf, sz, otype)); + } + opts++; + } + return (NNG_ENOTSUP); +} \ No newline at end of file -- cgit v1.2.3-70-g09d2