aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-03-18 12:46:31 -0700
committerGarrett D'Amore <garrett@damore.org>2018-03-18 12:46:31 -0700
commit8b979454d891b84da727a329906c4293fadc5f3c (patch)
treecb491c476080de11c7fc5b5868579f4ef86f4df4 /src
parent3a2af394a7d94ac5f924aaea6cbad825a9b05d75 (diff)
downloadnng-8b979454d891b84da727a329906c4293fadc5f3c.tar.gz
nng-8b979454d891b84da727a329906c4293fadc5f3c.tar.bz2
nng-8b979454d891b84da727a329906c4293fadc5f3c.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/compat/nanomsg/nn.c11
-rw-r--r--src/core/options.c36
-rw-r--r--src/core/options.h11
-rw-r--r--src/nng.c64
-rw-r--r--src/nng.h11
-rw-r--r--src/protocol/bus0/bus.c9
-rw-r--r--src/protocol/pair0/pair.c8
-rw-r--r--src/protocol/pair1/pair.c24
-rw-r--r--src/protocol/pipeline0/pull.c8
-rw-r--r--src/protocol/pipeline0/push.c8
-rw-r--r--src/protocol/pubsub0/pub.c8
-rw-r--r--src/protocol/pubsub0/sub.c8
-rw-r--r--src/protocol/reqrep0/rep.c8
-rw-r--r--src/protocol/reqrep0/req.c28
-rw-r--r--src/protocol/survey0/respond.c8
-rw-r--r--src/protocol/survey0/survey.c9
-rw-r--r--src/transport/tcp/tcp.c1
-rw-r--r--src/transport/tls/tls.c3
-rw-r--r--src/transport/ws/websocket.c2
19 files changed, 185 insertions, 80 deletions
diff --git a/src/compat/nanomsg/nn.c b/src/compat/nanomsg/nn.c
index 01b51503..fc29083e 100644
--- a/src/compat/nanomsg/nn.c
+++ b/src/compat/nanomsg/nn.c
@@ -164,7 +164,7 @@ nn_socket(int domain, int protocol)
return (-1);
}
if (domain == AF_SP_RAW) {
- if ((rv = nng_setopt_int(sock, NNG_OPT_RAW, 1)) != 0) {
+ if ((rv = nng_setopt_bool(sock, NNG_OPT_RAW, true)) != 0) {
nn_seterror(rv);
nng_close(sock);
return (-1);
@@ -624,14 +624,15 @@ static const struct {
static int
nn_getdomain(int s, void *valp, size_t *szp)
{
- int i;
- int rv;
+ int i;
+ bool b;
+ int rv;
- if ((rv = nng_getopt_int((nng_socket) s, NNG_OPT_RAW, &i)) != 0) {
+ if ((rv = nng_getopt_bool((nng_socket) s, NNG_OPT_RAW, &b)) != 0) {
nn_seterror(rv);
return (-1);
}
- i = i ? AF_SP_RAW : AF_SP;
+ i = b ? AF_SP_RAW : AF_SP;
memcpy(valp, &i, *szp < sizeof(int) ? *szp : sizeof(int));
*szp = sizeof(int);
return (0);
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 <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -42,6 +42,15 @@ nni_chkopt_int(const void *v, size_t sz, int minv, int maxv)
}
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)
{
size_t val;
@@ -72,6 +81,16 @@ nni_setopt_ms(nni_duration *dp, const void *v, size_t sz)
}
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)
{
int i;
@@ -187,6 +206,19 @@ nni_getopt_size(size_t u, void *val, size_t *sizep)
}
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)
{
size_t sz = sizeof(ptr);
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 <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// 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);
diff --git a/src/nng.c b/src/nng.c
index 4c2a58db..ad255d16 100644
--- a/src/nng.c
+++ b/src/nng.c
@@ -380,6 +380,12 @@ nng_dialer_setopt(nng_dialer id, const char *name, const void *v, size_t sz)
}
int
+nng_dialer_setopt_bool(nng_dialer id, const char *name, bool val)
+{
+ return (nng_dialer_setopt(id, name, &val, sizeof(val)));
+}
+
+int
nng_dialer_setopt_int(nng_dialer id, const char *name, int val)
{
return (nng_dialer_setopt(id, name, &val, sizeof(val)));
@@ -422,6 +428,13 @@ nng_dialer_getopt(nng_dialer id, const char *name, void *val, size_t *szp)
}
int
+nng_dialer_getopt_bool(nng_dialer id, const char *name, bool *valp)
+{
+ size_t sz = sizeof(*valp);
+ return (nng_dialer_getopt(id, name, valp, &sz));
+}
+
+int
nng_dialer_getopt_int(nng_dialer id, const char *name, int *valp)
{
size_t sz = sizeof(*valp);
@@ -464,6 +477,12 @@ nng_listener_setopt(
}
int
+nng_listener_setopt_bool(nng_listener id, const char *name, bool val)
+{
+ return (nng_listener_setopt(id, name, &val, sizeof(val)));
+}
+
+int
nng_listener_setopt_int(nng_listener id, const char *name, int val)
{
return (nng_listener_setopt(id, name, &val, sizeof(val)));
@@ -506,6 +525,13 @@ nng_listener_getopt(nng_listener id, const char *name, void *val, size_t *szp)
}
int
+nng_listener_getopt_bool(nng_listener id, const char *name, bool *valp)
+{
+ size_t sz = sizeof(*valp);
+ return (nng_listener_getopt(id, name, valp, &sz));
+}
+
+int
nng_listener_getopt_int(nng_listener id, const char *name, int *valp)
{
size_t sz = sizeof(*valp);
@@ -541,7 +567,7 @@ nng_listener_getopt_ms(nng_listener id, const char *name, nng_duration *valp)
}
static int
-nng_ep_close(uint32_t id)
+nng_ep_close(uint32_t id, int mode)
{
nni_ep *ep;
int rv;
@@ -549,6 +575,11 @@ nng_ep_close(uint32_t id)
if ((rv = nni_ep_find(&ep, id)) != 0) {
return (rv);
}
+ if (nni_ep_mode(ep) != mode) {
+ nni_ep_rele(ep);
+ return (NNG_ENOENT);
+ }
+
nni_ep_close(ep);
return (0);
}
@@ -556,13 +587,13 @@ nng_ep_close(uint32_t id)
int
nng_dialer_close(nng_dialer d)
{
- return (nng_ep_close((uint32_t) d));
+ return (nng_ep_close((uint32_t) d, NNI_EP_MODE_DIAL));
}
int
nng_listener_close(nng_listener l)
{
- return (nng_ep_close((uint32_t) l));
+ return (nng_ep_close((uint32_t) l, NNI_EP_MODE_LISTEN));
}
int
@@ -607,6 +638,12 @@ nng_setopt_int(nng_socket sid, const char *name, int val)
}
int
+nng_setopt_bool(nng_socket sid, const char *name, bool val)
+{
+ return (nng_setopt(sid, name, &val, sizeof(val)));
+}
+
+int
nng_setopt_size(nng_socket sid, const char *name, size_t val)
{
return (nng_setopt(sid, name, &val, sizeof(val)));
@@ -637,6 +674,13 @@ nng_setopt_string(nng_socket sid, const char *name, const char *val)
}
int
+nng_getopt_bool(nng_socket sid, const char *name, bool *valp)
+{
+ size_t sz = sizeof(*valp);
+ return (nng_getopt(sid, name, valp, &sz));
+}
+
+int
nng_getopt_int(nng_socket sid, const char *name, int *valp)
{
size_t sz = sizeof(*valp);
@@ -785,6 +829,13 @@ nng_pipe_getopt(nng_pipe id, const char *name, void *val, size_t *sizep)
}
int
+nng_pipe_getopt_bool(nng_pipe id, const char *name, bool *valp)
+{
+ size_t sz = sizeof(*valp);
+ return (nng_pipe_getopt(id, name, valp, &sz));
+}
+
+int
nng_pipe_getopt_int(nng_pipe id, const char *name, int *valp)
{
size_t sz = sizeof(*valp);
@@ -813,6 +864,13 @@ nng_pipe_getopt_ms(nng_pipe id, const char *name, nng_duration *valp)
}
int
+nng_pipe_getopt_ptr(nng_pipe id, const char *name, void **valp)
+{
+ size_t sz = sizeof(*valp);
+ return (nng_pipe_getopt(id, name, valp, &sz));
+}
+
+int
nng_pipe_close(nng_pipe id)
{
int rv;
diff --git a/src/nng.h b/src/nng.h
index 84680dd1..2f8c2976 100644
--- a/src/nng.h
+++ b/src/nng.h
@@ -95,14 +95,17 @@ NNG_DECL void nng_closeall(void);
// nng_setopt sets an option for a specific socket.
NNG_DECL int nng_setopt(nng_socket, const char *, const void *, size_t);
+NNG_DECL int nng_setopt_bool(nng_socket, const char *, bool);
NNG_DECL int nng_setopt_int(nng_socket, const char *, int);
NNG_DECL int nng_setopt_ms(nng_socket, const char *, nng_duration);
NNG_DECL int nng_setopt_size(nng_socket, const char *, size_t);
NNG_DECL int nng_setopt_uint64(nng_socket, const char *, uint64_t);
NNG_DECL int nng_setopt_string(nng_socket, const char *, const char *);
+NNG_DECL int nng_setopt_ptr(nng_socket, const char *, void *);
// nng_socket_getopt obtains the option for a socket.
NNG_DECL int nng_getopt(nng_socket, const char *, void *, size_t *);
+NNG_DECL int nng_getopt_bool(nng_socket, const char *, bool *);
NNG_DECL int nng_getopt_int(nng_socket, const char *, int *);
NNG_DECL int nng_getopt_ms(nng_socket, const char *, nng_duration *);
NNG_DECL int nng_getopt_size(nng_socket, const char *, size_t *);
@@ -152,6 +155,7 @@ NNG_DECL int nng_listener_close(nng_listener);
// nng_dialer_setopt sets an option for a specific dialer. Note
// dialer options may not be altered on a running dialer.
NNG_DECL int nng_dialer_setopt(nng_dialer, const char *, const void *, size_t);
+NNG_DECL int nng_dialer_setopt_bool(nng_dialer, const char *, bool);
NNG_DECL int nng_dialer_setopt_int(nng_dialer, const char *, int);
NNG_DECL int nng_dialer_setopt_ms(nng_dialer, const char *, nng_duration);
NNG_DECL int nng_dialer_setopt_size(nng_dialer, const char *, size_t);
@@ -163,6 +167,7 @@ NNG_DECL int nng_dialer_setopt_string(nng_dialer, const char *, const char *);
// fail for options that a particular dialer is not interested in,
// even if they were set on the socket.
NNG_DECL int nng_dialer_getopt(nng_dialer, const char *, void *, size_t *);
+NNG_DECL int nng_dialer_getopt_bool(nng_dialer, const char *, bool *);
NNG_DECL int nng_dialer_getopt_int(nng_dialer, const char *, int *);
NNG_DECL int nng_dialer_getopt_ms(nng_dialer, const char *, nng_duration *);
NNG_DECL int nng_dialer_getopt_size(nng_dialer, const char *, size_t *);
@@ -175,6 +180,7 @@ NNG_DECL int nng_dialer_getopt_ptr(nng_dialer, const char *, void **);
// on a running listener.
NNG_DECL int nng_listener_setopt(
nng_listener, const char *, const void *, size_t);
+NNG_DECL int nng_listener_setopt_bool(nng_listener, const char *, bool);
NNG_DECL int nng_listener_setopt_int(nng_listener, const char *, int);
NNG_DECL int nng_listener_setopt_ms(nng_listener, const char *, nng_duration);
NNG_DECL int nng_listener_setopt_size(nng_listener, const char *, size_t);
@@ -187,6 +193,7 @@ NNG_DECL int nng_listener_setopt_string(
// fail for options that a particular listener is not interested in,
// even if they were set on the socket.
NNG_DECL int nng_listener_getopt(nng_listener, const char *, void *, size_t *);
+NNG_DECL int nng_listener_getopt_bool(nng_listener, const char *, bool *);
NNG_DECL int nng_listener_getopt_int(nng_listener, const char *, int *);
NNG_DECL int nng_listener_getopt_ms(
nng_listener, const char *, nng_duration *);
@@ -394,10 +401,12 @@ NNG_DECL int nng_msg_getopt(nng_msg *, int, void *, size_t *);
// example during a connection notification, to disconnect a pipe that
// is associated with an invalid or untrusted remote peer.
NNG_DECL int nng_pipe_getopt(nng_pipe, const char *, void *, size_t *);
+NNG_DECL int nng_pipe_getopt_bool(nng_pipe, const char *, bool *);
NNG_DECL int nng_pipe_getopt_int(nng_pipe, const char *, int *);
NNG_DECL int nng_pipe_getopt_ms(nng_pipe, const char *, nng_duration *);
NNG_DECL int nng_pipe_getopt_size(nng_pipe, const char *, size_t *);
NNG_DECL int nng_pipe_getopt_uint64(nng_pipe, const char *, uint64_t *);
+NNG_DECL int nng_pipe_getopt_ptr(nng_pipe, const char *, void **);
NNG_DECL int nng_pipe_close(nng_pipe);
// Flags.
@@ -472,7 +481,7 @@ enum nng_flag_enum {
// authentication is disabled with `NNG_TLS_AUTH_MODE_NONE`.
#define NNG_OPT_TLS_VERIFIED "tls-verified"
-// XXX: TBD: priorities, socket names, ipv4only
+// XXX: TBD: priorities, ipv4only, TCP options
// Statistics. These are for informational purposes only, and subject
// to change without notice. The API for accessing these is stable,
diff --git a/src/protocol/bus0/bus.c b/src/protocol/bus0/bus.c
index 1176bf01..d2b51cd4 100644
--- a/src/protocol/bus0/bus.c
+++ b/src/protocol/bus0/bus.c
@@ -8,6 +8,7 @@
// found online at https://opensource.org/licenses/MIT.
//
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
@@ -41,7 +42,7 @@ static void bus0_pipe_putq_cb(void *);
// bus0_sock is our per-socket protocol private structure.
struct bus0_sock {
- int raw;
+ bool raw;
nni_aio * aio_getq;
nni_list pipes;
nni_mtx mtx;
@@ -88,7 +89,7 @@ bus0_sock_init(void **sp, nni_sock *nsock)
bus0_sock_fini(s);
return (rv);
}
- s->raw = 0;
+ s->raw = false;
s->uwq = nni_sock_sendq(nsock);
s->urq = nni_sock_recvq(nsock);
@@ -336,14 +337,14 @@ static int
bus0_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
bus0_sock *s = arg;
- return (nni_setopt_int(&s->raw, buf, sz, 0, 1));
+ return (nni_setopt_bool(&s->raw, buf, sz));
}
static int
bus0_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
bus0_sock *s = arg;
- return (nni_getopt_int(s->raw, buf, szp));
+ return (nni_getopt_bool(s->raw, buf, szp));
}
static void
diff --git a/src/protocol/pair0/pair.c b/src/protocol/pair0/pair.c
index d3591df9..9e9dfe10 100644
--- a/src/protocol/pair0/pair.c
+++ b/src/protocol/pair0/pair.c
@@ -36,7 +36,7 @@ struct pair0_sock {
pair0_pipe *ppipe;
nni_msgq * uwq;
nni_msgq * urq;
- int raw;
+ bool raw;
nni_mtx mtx;
};
@@ -63,7 +63,7 @@ pair0_sock_init(void **sp, nni_sock *nsock)
}
nni_mtx_init(&s->mtx);
s->ppipe = NULL;
- s->raw = 0;
+ s->raw = false;
s->uwq = nni_sock_sendq(nsock);
s->urq = nni_sock_recvq(nsock);
*sp = s;
@@ -235,14 +235,14 @@ static int
pair0_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
pair0_sock *s = arg;
- return (nni_setopt_int(&s->raw, buf, sz, 0, 1));
+ return (nni_setopt_bool(&s->raw, buf, sz));
}
static int
pair0_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
pair0_sock *s = arg;
- return (nni_getopt_int(s->raw, buf, szp));
+ return (nni_getopt_bool(s->raw, buf, szp));
}
static void
diff --git a/src/protocol/pair1/pair.c b/src/protocol/pair1/pair.c
index 3f6f63fc..b4519221 100644
--- a/src/protocol/pair1/pair.c
+++ b/src/protocol/pair1/pair.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -37,13 +37,13 @@ static void pair1_pipe_fini(void *);
struct pair1_sock {
nni_msgq * uwq;
nni_msgq * urq;
- int raw;
+ bool raw;
int ttl;
nni_mtx mtx;
nni_idhash *pipes;
nni_list plist;
- int started;
- int poly;
+ bool started;
+ bool poly;
nni_aio * aio_getq;
};
@@ -94,8 +94,8 @@ pair1_sock_init(void **sp, nni_sock *nsock)
return (rv);
}
- s->raw = 0;
- s->poly = 0;
+ s->raw = false;
+ s->poly = false;
s->uwq = nni_sock_sendq(nsock);
s->urq = nni_sock_recvq(nsock);
s->ttl = 8;
@@ -167,7 +167,7 @@ pair1_pipe_start(void *arg)
}
}
nni_list_append(&s->plist, p);
- s->started = 1;
+ s->started = true;
nni_mtx_unlock(&s->mtx);
// Schedule a getq. In polyamorous mode we get on the per pipe
@@ -402,7 +402,7 @@ pair1_sock_setopt_raw(void *arg, const void *buf, size_t sz)
pair1_sock *s = arg;
int rv;
nni_mtx_lock(&s->mtx);
- rv = s->started ? NNG_ESTATE : nni_setopt_int(&s->raw, buf, sz, 0, 1);
+ rv = s->started ? NNG_ESTATE : nni_setopt_bool(&s->raw, buf, sz);
nni_mtx_unlock(&s->mtx);
return (rv);
}
@@ -411,7 +411,7 @@ static int
pair1_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
pair1_sock *s = arg;
- return (nni_getopt_int(s->raw, buf, szp));
+ return (nni_getopt_bool(s->raw, buf, szp));
}
static int
@@ -438,7 +438,7 @@ pair1_sock_setopt_poly(void *arg, const void *buf, size_t sz)
pair1_sock *s = arg;
int rv;
nni_mtx_lock(&s->mtx);
- rv = s->started ? NNG_ESTATE : nni_setopt_int(&s->poly, buf, sz, 0, 1);
+ rv = s->started ? NNG_ESTATE : nni_setopt_bool(&s->poly, buf, sz);
nni_mtx_unlock(&s->mtx);
return (rv);
}
@@ -447,7 +447,7 @@ static int
pair1_sock_getopt_poly(void *arg, void *buf, size_t *szp)
{
pair1_sock *s = arg;
- return (nni_getopt_int(s->poly, buf, szp));
+ return (nni_getopt_bool(s->poly, buf, szp));
}
static void
diff --git a/src/protocol/pipeline0/pull.c b/src/protocol/pipeline0/pull.c
index ccc1ef40..5e0a9d00 100644
--- a/src/protocol/pipeline0/pull.c
+++ b/src/protocol/pipeline0/pull.c
@@ -34,7 +34,7 @@ static void pull0_putq(pull0_pipe *, nni_msg *);
// pull0_sock is our per-socket protocol private structure.
struct pull0_sock {
nni_msgq *urq;
- int raw;
+ bool raw;
};
// pull0_pipe is our per-pipe protocol private structure.
@@ -53,7 +53,7 @@ pull0_sock_init(void **sp, nni_sock *sock)
if ((s = NNI_ALLOC_STRUCT(s)) == NULL) {
return (NNG_ENOMEM);
}
- s->raw = 0;
+ s->raw = false;
s->urq = nni_sock_recvq(sock);
*sp = s;
@@ -184,14 +184,14 @@ static int
pull0_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
pull0_sock *s = arg;
- return (nni_setopt_int(&s->raw, buf, sz, 0, 1));
+ return (nni_setopt_bool(&s->raw, buf, sz));
}
static int
pull0_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
pull0_sock *s = arg;
- return (nni_getopt_int(s->raw, buf, szp));
+ return (nni_getopt_bool(s->raw, buf, szp));
}
static void
diff --git a/src/protocol/pipeline0/push.c b/src/protocol/pipeline0/push.c
index e77bfe99..a0dfa397 100644
--- a/src/protocol/pipeline0/push.c
+++ b/src/protocol/pipeline0/push.c
@@ -36,7 +36,7 @@ static void push0_getq_cb(void *);
// push0_sock is our per-socket protocol private structure.
struct push0_sock {
nni_msgq *uwq;
- int raw;
+ bool raw;
};
// push0_pipe is our per-pipe protocol private structure.
@@ -58,7 +58,7 @@ push0_sock_init(void **sp, nni_sock *sock)
if ((s = NNI_ALLOC_STRUCT(s)) == NULL) {
return (NNG_ENOMEM);
}
- s->raw = 0;
+ s->raw = false;
s->uwq = nni_sock_sendq(sock);
*sp = s;
return (0);
@@ -201,14 +201,14 @@ static int
push0_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
push0_sock *s = arg;
- return (nni_setopt_int(&s->raw, buf, sz, 0, 1));
+ return (nni_setopt_bool(&s->raw, buf, sz));
}
static int
push0_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
push0_sock *s = arg;
- return (nni_getopt_int(s->raw, buf, szp));
+ return (nni_getopt_bool(s->raw, buf, szp));
}
static void
diff --git a/src/protocol/pubsub0/pub.c b/src/protocol/pubsub0/pub.c
index 33ecb5ba..ff110d56 100644
--- a/src/protocol/pubsub0/pub.c
+++ b/src/protocol/pubsub0/pub.c
@@ -40,7 +40,7 @@ static void pub0_pipe_fini(void *);
// pub0_sock is our per-socket protocol private structure.
struct pub0_sock {
nni_msgq *uwq;
- int raw;
+ bool raw;
nni_aio * aio_getq;
nni_list pipes;
nni_mtx mtx;
@@ -83,7 +83,7 @@ pub0_sock_init(void **sp, nni_sock *sock)
return (rv);
}
- s->raw = 0;
+ s->raw = false;
NNI_LIST_INIT(&s->pipes, pub0_pipe, node);
s->uwq = nni_sock_sendq(sock);
@@ -277,14 +277,14 @@ static int
pub0_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
pub0_sock *s = arg;
- return (nni_setopt_int(&s->raw, buf, sz, 0, 1));
+ return (nni_setopt_bool(&s->raw, buf, sz));
}
static int
pub0_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
pub0_sock *s = arg;
- return (nni_getopt_int(s->raw, buf, szp));
+ return (nni_getopt_bool(s->raw, buf, szp));
}
static void
diff --git a/src/protocol/pubsub0/sub.c b/src/protocol/pubsub0/sub.c
index 8803ab19..d9d0d5f3 100644
--- a/src/protocol/pubsub0/sub.c
+++ b/src/protocol/pubsub0/sub.c
@@ -44,7 +44,7 @@ struct sub0_topic {
struct sub0_sock {
nni_list topics;
nni_msgq *urq;
- int raw;
+ bool raw;
nni_mtx lk;
};
@@ -66,7 +66,7 @@ sub0_sock_init(void **sp, nni_sock *sock)
}
nni_mtx_init(&s->lk);
NNI_LIST_INIT(&s->topics, sub0_topic, node);
- s->raw = 0;
+ s->raw = false;
s->urq = nni_sock_recvq(sock);
*sp = s;
@@ -279,14 +279,14 @@ static int
sub0_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
sub0_sock *s = arg;
- return (nni_setopt_int(&s->raw, buf, sz, 0, 1));
+ return (nni_setopt_bool(&s->raw, buf, sz));
}
static int
sub0_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
sub0_sock *s = arg;
- return (nni_getopt_int(s->raw, buf, szp));
+ return (nni_getopt_bool(s->raw, buf, szp));
}
static void
diff --git a/src/protocol/reqrep0/rep.c b/src/protocol/reqrep0/rep.c
index f1a3a409..9906de4b 100644
--- a/src/protocol/reqrep0/rep.c
+++ b/src/protocol/reqrep0/rep.c
@@ -41,7 +41,7 @@ struct rep0_sock {
nni_msgq * uwq;
nni_msgq * urq;
nni_mtx lk;
- int raw;
+ bool raw;
int ttl;
nni_idhash *pipes;
char * btrace;
@@ -92,7 +92,7 @@ rep0_sock_init(void **sp, nni_sock *sock)
}
s->ttl = 8; // Per RFC
- s->raw = 0;
+ s->raw = false;
s->btrace = NULL;
s->btrace_len = 0;
s->uwq = nni_sock_sendq(sock);
@@ -359,7 +359,7 @@ rep0_sock_setopt_raw(void *arg, const void *buf, size_t sz)
int rv;
nni_mtx_lock(&s->lk);
- rv = nni_setopt_int(&s->raw, buf, sz, 0, 1);
+ rv = nni_setopt_bool(&s->raw, buf, sz);
nni_mtx_unlock(&s->lk);
return (rv);
}
@@ -368,7 +368,7 @@ static int
rep0_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
rep0_sock *s = arg;
- return (nni_getopt_int(s->raw, buf, szp));
+ return (nni_getopt_bool(s->raw, buf, szp));
}
static int
diff --git a/src/protocol/reqrep0/req.c b/src/protocol/reqrep0/req.c
index 2a641933..d87a5d1f 100644
--- a/src/protocol/reqrep0/req.c
+++ b/src/protocol/reqrep0/req.c
@@ -39,9 +39,9 @@ struct req0_sock {
nni_msgq * urq;
nni_duration retry;
nni_time resend;
- int raw;
- int wantw;
- int closed;
+ bool raw;
+ bool wantw;
+ bool closed;
int ttl;
nni_msg * reqmsg;
@@ -96,8 +96,8 @@ req0_sock_init(void **sp, nni_sock *sock)
s->nextid = nni_random();
s->retry = NNI_SECOND * 60;
s->reqmsg = NULL;
- s->raw = 0;
- s->wantw = 0;
+ s->raw = false;
+ s->wantw = false;
s->resend = NNI_TIME_ZERO;
s->ttl = 8;
s->uwq = nni_sock_sendq(sock);
@@ -119,7 +119,7 @@ req0_sock_close(void *arg)
req0_sock *s = arg;
nni_mtx_lock(&s->mtx);
- s->closed = 1;
+ s->closed = true;
nni_mtx_unlock(&s->mtx);
nni_timer_cancel(&s->timer);
@@ -243,7 +243,7 @@ req0_pipe_stop(void *arg)
// schedule immediate resend.
s->pendpipe = NULL;
s->resend = NNI_TIME_ZERO;
- s->wantw = 1;
+ s->wantw = true;
req0_resend(s);
}
nni_mtx_unlock(&s->mtx);
@@ -253,14 +253,14 @@ static int
req0_sock_setopt_raw(void *arg, const void *buf, size_t sz)
{
req0_sock *s = arg;
- return (nni_setopt_int(&s->raw, buf, sz, 0, 1));
+ return (nni_setopt_bool(&s->raw, buf, sz));
}
static int
req0_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
req0_sock *s = arg;
- return (nni_getopt_int(s->raw, buf, szp));
+ return (nni_getopt_bool(s->raw, buf, szp));
}
static int
@@ -442,7 +442,7 @@ req0_timeout(void *arg)
nni_mtx_lock(&s->mtx);
if (s->reqmsg != NULL) {
- s->wantw = 1;
+ s->wantw = true;
req0_resend(s);
}
nni_mtx_unlock(&s->mtx);
@@ -467,13 +467,13 @@ req0_resend(req0_sock *s)
}
if (s->wantw) {
- s->wantw = 0;
+ s->wantw = false;
if (nni_msg_dup(&msg, s->reqmsg) != 0) {
// Failed to alloc message, reschedule it. Also,
// mark that we have a message we want to resend,
// in case something comes available.
- s->wantw = 1;
+ s->wantw = true;
nni_timer_schedule(&s->timer, nni_clock() + s->retry);
return;
}
@@ -484,7 +484,7 @@ req0_resend(req0_sock *s)
// No pipes ready to process us. Note that we have
// something to send, and schedule it.
nni_msg_free(msg);
- s->wantw = 1;
+ s->wantw = true;
return;
}
@@ -550,7 +550,7 @@ req0_sock_send(void *arg, nni_aio *aio)
s->reqmsg = msg;
// Schedule for immediate send
s->resend = NNI_TIME_ZERO;
- s->wantw = 1;
+ s->wantw = true;
req0_resend(s);
diff --git a/src/protocol/survey0/respond.c b/src/protocol/survey0/respond.c
index 2f0514a9..c73f5720 100644
--- a/src/protocol/survey0/respond.c
+++ b/src/protocol/survey0/respond.c
@@ -40,7 +40,7 @@ static void resp0_pipe_fini(void *);
struct resp0_sock {
nni_msgq * urq;
nni_msgq * uwq;
- int raw;
+ bool raw;
int ttl;
nni_idhash *pipes;
char * btrace;
@@ -93,7 +93,7 @@ resp0_sock_init(void **sp, nni_sock *nsock)
}
s->ttl = 8; // Per RFC
- s->raw = 0;
+ s->raw = false;
s->btrace = NULL;
s->btrace_len = 0;
s->urq = nni_sock_recvq(nsock);
@@ -353,7 +353,7 @@ resp0_sock_setopt_raw(void *arg, const void *buf, size_t sz)
int rv;
nni_mtx_lock(&s->mtx);
- rv = nni_setopt_int(&s->raw, buf, sz, 0, 1);
+ rv = nni_setopt_bool(&s->raw, buf, sz);
nni_mtx_unlock(&s->mtx);
return (rv);
}
@@ -362,7 +362,7 @@ static int
resp0_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
resp0_sock *s = arg;
- return (nni_getopt_int(s->raw, buf, szp));
+ return (nni_getopt_bool(s->raw, buf, szp));
}
static int
diff --git a/src/protocol/survey0/survey.c b/src/protocol/survey0/survey.c
index 637ce2e2..864287ed 100644
--- a/src/protocol/survey0/survey.c
+++ b/src/protocol/survey0/survey.c
@@ -39,9 +39,8 @@ static void surv0_timeout(void *);
struct surv0_sock {
nni_duration survtime;
nni_time expire;
- int raw;
+ bool raw;
int ttl;
- int closing;
uint32_t nextid; // next id
uint32_t survid; // outstanding request ID (big endian)
nni_list pipes;
@@ -93,7 +92,7 @@ surv0_sock_init(void **sp, nni_sock *nsock)
nni_timer_init(&s->timer, surv0_timeout, s);
s->nextid = nni_random();
- s->raw = 0;
+ s->raw = false;
s->survtime = NNI_SECOND;
s->expire = NNI_TIME_ZERO;
s->uwq = nni_sock_sendq(nsock);
@@ -282,7 +281,7 @@ surv0_sock_setopt_raw(void *arg, const void *buf, size_t sz)
int rv;
nni_mtx_lock(&s->mtx);
- if ((rv = nni_setopt_int(&s->raw, buf, sz, 0, 1)) == 0) {
+ if ((rv = nni_setopt_bool(&s->raw, buf, sz)) == 0) {
s->survid = 0;
nni_timer_cancel(&s->timer);
}
@@ -294,7 +293,7 @@ static int
surv0_sock_getopt_raw(void *arg, void *buf, size_t *szp)
{
surv0_sock *s = arg;
- return (nni_getopt_int(s->raw, buf, szp));
+ return (nni_getopt_bool(s->raw, buf, szp));
}
static int
diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c
index 1b4e6dc2..a74f1097 100644
--- a/src/transport/tcp/tcp.c
+++ b/src/transport/tcp/tcp.c
@@ -49,7 +49,6 @@ struct nni_tcp_ep {
uint16_t proto;
size_t rcvmax;
nni_duration linger;
- int ipv4only;
nni_aio * aio;
nni_aio * user_aio;
nni_url * url;
diff --git a/src/transport/tls/tls.c b/src/transport/tls/tls.c
index 534b955d..59066f5f 100644
--- a/src/transport/tls/tls.c
+++ b/src/transport/tls/tls.c
@@ -55,7 +55,6 @@ struct nni_tls_ep {
uint16_t proto;
size_t rcvmax;
nni_duration linger;
- int ipv4only;
int authmode;
nni_aio * aio;
nni_aio * user_aio;
@@ -893,7 +892,7 @@ tls_getopt_verified(void *arg, void *v, size_t *szp)
{
nni_tls_pipe *p = arg;
- return (nni_getopt_int(nni_tls_verified(p->tls) ? 1 : 0, v, szp));
+ return (nni_getopt_bool(nni_tls_verified(p->tls), v, szp));
}
static nni_tran_pipe_option nni_tls_pipe_options[] = {
diff --git a/src/transport/ws/websocket.c b/src/transport/ws/websocket.c
index a8cdcbb0..f0172385 100644
--- a/src/transport/ws/websocket.c
+++ b/src/transport/ws/websocket.c
@@ -532,7 +532,7 @@ static int
ws_pipe_getopt_tls_verified(void *arg, void *v, size_t *szp)
{
ws_pipe *p = arg;
- return (nni_getopt_int(nni_ws_tls_verified(p->ws) ? 1 : 0, v, szp));
+ return (nni_getopt_bool(nni_ws_tls_verified(p->ws), v, szp));
}
static nni_tran_pipe_option ws_pipe_options[] = {