aboutsummaryrefslogtreecommitdiff
path: root/src/core/options.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-12-29 16:16:57 -0800
committerGarrett D'Amore <garrett@damore.org>2018-12-29 16:16:57 -0800
commit5b35daaf2fe6c6fbe0b15740efbffe16ff278e6c (patch)
tree24c383103cc3ff3e98e2e8179d0633e9b2f6010a /src/core/options.c
parentd3bd35ab49ad74528fd9e34cce9016d74dd91943 (diff)
downloadnng-5b35daaf2fe6c6fbe0b15740efbffe16ff278e6c.tar.gz
nng-5b35daaf2fe6c6fbe0b15740efbffe16ff278e6c.tar.bz2
nng-5b35daaf2fe6c6fbe0b15740efbffe16ff278e6c.zip
IPC option rework (pipe/conn) to reduce code duplication.
Diffstat (limited to 'src/core/options.c')
-rw-r--r--src/core/options.c32
1 files changed, 32 insertions, 0 deletions
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