From 8b979454d891b84da727a329906c4293fadc5f3c Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 18 Mar 2018 12:46:31 -0700 Subject: fixes #295 boolean options should use C99 bool type fixes #275 nng_pipe_getopt_ptr() missing? fixes #285 nng_setopt_ptr MIS fixes #297 nng_listener/dialer_close does not validate mode This change adds some missing APIs, and changes others. In particular, certain options are now of type bool, with size of just one. This is a *breaking* change for code that uses those options -- NNG_OPT_RAW, NNG_OPT_PAIR1_POLY, NNG_OPT_TLS_VERIFIED. --- src/core/options.c | 36 ++++++++++++++++++++++++++++++++++-- src/core/options.h | 11 +++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) (limited to 'src/core') diff --git a/src/core/options.c b/src/core/options.c index ef7420d6..f51a6abe 100644 --- a/src/core/options.c +++ b/src/core/options.c @@ -1,6 +1,6 @@ // -// Copyright 2017 Garrett D'Amore -// Copyright 2017 Capitar IT Group BV +// Copyright 2018 Staysail Systems, Inc. +// Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -41,6 +41,15 @@ nni_chkopt_int(const void *v, size_t sz, int minv, int maxv) return (0); } +int +nni_chkopt_bool(size_t sz) +{ + if (sz != sizeof(bool)) { + return (NNG_EINVAL); + } + return (0); +} + int nni_chkopt_size(const void *v, size_t sz, size_t minv, size_t maxv) { @@ -71,6 +80,16 @@ nni_setopt_ms(nni_duration *dp, const void *v, size_t sz) return (0); } +int +nni_setopt_bool(bool *bp, const void *v, size_t sz) +{ + if (sz != sizeof(*bp)) { + return (NNG_EINVAL); + } + memcpy(bp, v, sizeof(*bp)); + return (0); +} + int nni_setopt_int(int *ip, const void *v, size_t sz, int minv, int maxv) { @@ -186,6 +205,19 @@ nni_getopt_size(size_t u, void *val, size_t *sizep) return (0); } +int +nni_getopt_bool(bool b, void *val, size_t *sizep) +{ + size_t sz = sizeof(b); + + if (sz > *sizep) { + sz = *sizep; + } + *sizep = sizeof(b); + memcpy(val, &b, sz); + return (0); +} + int nni_getopt_ptr(void *ptr, void *val, size_t *sizep) { diff --git a/src/core/options.h b/src/core/options.h index e9aa16dd..f5743aae 100644 --- a/src/core/options.h +++ b/src/core/options.h @@ -1,6 +1,6 @@ // -// Copyright 2017 Garrett D'Amore -// Copyright 2017 Capitar IT Group BV +// Copyright 2018 Staysail Systems, Inc. +// Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -28,6 +28,12 @@ extern int nni_setopt_ms(nni_duration *, const void *, size_t); // nni_getopt_duration gets the duration. extern int nni_getopt_ms(nni_duration, void *, size_t *); +// nni_setopt_bool sets a bool, or _Bool +extern int nni_setopt_bool(bool *, const void *, size_t); + +// nni_getopt_bool gets a bool (or _Bool) +extern int nni_getopt_bool(bool, void *, size_t *); + // nni_setopt_int sets an integer, which must be between the minimum and // maximum values (inclusive). extern int nni_setopt_int(int *, const void *, size_t, int, int); @@ -61,6 +67,7 @@ extern int nni_getopt_size(size_t, void *, size_t *); // nni_getopt_ptr obtains a pointer option. extern int nni_getopt_ptr(void *, void *, size_t *); +extern int nni_chkopt_bool(size_t); extern int nni_chkopt_ms(const void *, size_t); extern int nni_chkopt_int(const void *, size_t, int, int); extern int nni_chkopt_size(const void *, size_t, size_t, size_t); -- cgit v1.2.3-70-g09d2