aboutsummaryrefslogtreecommitdiff
path: root/src/nng.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-12 10:16:54 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-12 10:16:54 -0700
commit9b4d9e71a63cafcee0edee734847bba28d9fea35 (patch)
treec65290fb84bf3168af439ef8e92a5f1370aa2ceb /src/nng.c
parent0584aa354014e91a9036bc51bad438e8fddaf15f (diff)
downloadnng-9b4d9e71a63cafcee0edee734847bba28d9fea35.tar.gz
nng-9b4d9e71a63cafcee0edee734847bba28d9fea35.tar.bz2
nng-9b4d9e71a63cafcee0edee734847bba28d9fea35.zip
Convenience option accesor functions.
This adds functions that know about option sizes and make them easier to use. While here I added some validation of those, and cleaned up a few tests slightly. Note that we do not need to use the nng_impl.h for most tests. More of them need to be cleaned up.
Diffstat (limited to 'src/nng.c')
-rw-r--r--src/nng.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/nng.c b/src/nng.c
index 61aaa9c4..a34619da 100644
--- a/src/nng.c
+++ b/src/nng.c
@@ -296,6 +296,46 @@ nng_getopt(nng_socket sid, int opt, void *val, size_t *szp)
return (rv);
}
+// Convenience option wrappers.
+int
+nng_setopt_int(nng_socket sid, int opt, int val)
+{
+ return (nng_setopt(sid, opt, &val, sizeof(val)));
+}
+
+int
+nng_setopt_size(nng_socket sid, int opt, size_t val)
+{
+ return (nng_setopt(sid, opt, &val, sizeof(val)));
+}
+
+int
+nng_setopt_duration(nng_socket sid, int opt, uint64_t val)
+{
+ return (nng_setopt(sid, opt, &val, sizeof(val)));
+}
+
+int
+nng_getopt_int(nng_socket sid, int opt, int *valp)
+{
+ size_t sz = sizeof(*valp);
+ return (nng_getopt(sid, opt, valp, &sz));
+}
+
+int
+nng_getopt_size(nng_socket sid, int opt, size_t *valp)
+{
+ size_t sz = sizeof(*valp);
+ return (nng_getopt(sid, opt, valp, &sz));
+}
+
+int
+nng_getopt_duration(nng_socket sid, int opt, uint64_t *valp)
+{
+ size_t sz = sizeof(*valp);
+ return (nng_getopt(sid, opt, valp, &sz));
+}
+
nng_notify *
nng_setnotify(nng_socket sid, int mask, nng_notify_func fn, void *arg)
{