From 45f455064b5704f3d5ed8ecf9f197a18fe72ee59 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 4 Apr 2018 12:37:34 -0700 Subject: 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. --- src/core/socket.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/core/socket.c') 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 @@ -192,6 +192,13 @@ nni_sock_getopt_recvfd(nni_sock *s, void *buf, size_t *szp, int typ) return (nni_copyout_int(fd, buf, szp, 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) { @@ -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; -- cgit v1.2.3-70-g09d2