summaryrefslogtreecommitdiff
path: root/src/core/socket.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-04-04 12:37:34 -0700
committerGarrett D'Amore <garrett@damore.org>2018-04-04 13:13:24 -0700
commit45f455064b5704f3d5ed8ecf9f197a18fe72ee59 (patch)
tree76a626029f3a5a818b113b7e4342efaf6220a03f /src/core/socket.c
parent505a9bce029e51540739c853a6c9eef0ecfb2e90 (diff)
downloadnng-45f455064b5704f3d5ed8ecf9f197a18fe72ee59.tar.gz
nng-45f455064b5704f3d5ed8ecf9f197a18fe72ee59.tar.bz2
nng-45f455064b5704f3d5ed8ecf9f197a18fe72ee59.zip
fixes #331 replace NNG_OPT_RAW option with constructor
This makes the raw mode something that is immutable, determined at socket construction. This is an enabling change for the separate context support coming soon. As a result, this is an API breaking change for users of the raw mode option (NNG_OPT_RAW). There aren't many of them out there. Cooked mode is entirely unaffected. There are changes to tests and documentation included.
Diffstat (limited to 'src/core/socket.c')
-rw-r--r--src/core/socket.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/core/socket.c b/src/core/socket.c
index 40ef32f3..62950b1c 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -193,6 +193,13 @@ nni_sock_getopt_recvfd(nni_sock *s, void *buf, size_t *szp, int typ)
}
static int
+nni_sock_getopt_raw(nni_sock *s, void *buf, size_t *szp, int typ)
+{
+ bool raw = ((nni_sock_flags(s) & NNI_PROTO_FLAG_RAW) != 0);
+ return (nni_copyout_bool(raw, buf, szp, typ));
+}
+
+static int
nni_sock_setopt_recvtimeo(nni_sock *s, const void *buf, size_t sz, int typ)
{
return (nni_copyin_ms(&s->s_rcvtimeo, buf, sz, typ));
@@ -347,6 +354,12 @@ static const nni_socket_option nni_sock_options[] = {
.so_getopt = nni_sock_getopt_sockname,
.so_setopt = nni_sock_setopt_sockname,
},
+ {
+ .so_name = NNG_OPT_RAW,
+ .so_type = NNI_TYPE_BOOL,
+ .so_getopt = nni_sock_getopt_raw,
+ .so_setopt = NULL,
+ },
// terminate list
{
.so_name = NULL,
@@ -920,7 +933,8 @@ nni_sock_setopt(nni_sock *s, const char *name, const void *v, size_t sz, int t)
return (NNG_ECLOSED);
}
- // Protocol options.
+ // Protocol options. The protocol can override options that
+ // the socket framework would otherwise supply, like buffer sizes.
for (pso = s->s_sock_ops.sock_options; pso->pso_name != NULL; pso++) {
if (strcmp(pso->pso_name, name) != 0) {
continue;
@@ -1076,7 +1090,8 @@ nni_sock_getopt(nni_sock *s, const char *name, void *val, size_t *szp, int t)
return (NNG_ECLOSED);
}
- // Protocol specific options.
+ // Protocol specific options. The protocol can override
+ // options like the send buffer or notification descriptors this way.
for (pso = s->s_sock_ops.sock_options; pso->pso_name != NULL; pso++) {
if (strcmp(name, pso->pso_name) != 0) {
continue;