From 9b4d9e71a63cafcee0edee734847bba28d9fea35 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 12 Aug 2017 10:16:54 -0700 Subject: 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. --- src/nng.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/nng.c') 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) { -- cgit v1.2.3-70-g09d2