aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/device.c19
-rw-r--r--src/core/protocol.h4
-rw-r--r--src/core/socket.c19
3 files changed, 38 insertions, 4 deletions
diff --git a/src/core/device.c b/src/core/device.c
index 0eaec30e..6def9f64 100644
--- a/src/core/device.c
+++ b/src/core/device.c
@@ -105,6 +105,8 @@ nni_device_init(nni_device_data **dp, nni_sock *s1, nni_sock *s2)
nni_device_data *dd;
int npath = 2;
int i;
+ bool raw;
+ size_t rsz;
// Specifying either of these as null turns the device into
// a loopback reflector.
@@ -123,6 +125,21 @@ nni_device_init(nni_device_data **dp, nni_sock *s1, nni_sock *s2)
return (NNG_EINVAL);
}
+ raw = false;
+ rsz = sizeof(raw);
+ if (((nni_sock_getopt(s1, NNG_OPT_RAW, &raw, &rsz, NNI_TYPE_BOOL) !=
+ 0)) ||
+ (!raw)) {
+ return (NNG_EINVAL);
+ }
+
+ rsz = sizeof(raw);
+ if (((nni_sock_getopt(s2, NNG_OPT_RAW, &raw, &rsz, NNI_TYPE_BOOL) !=
+ 0)) ||
+ (!raw)) {
+ return (NNG_EINVAL);
+ }
+
// Note we assume that since they peers, we only need to look
// at the receive flags -- the other side is assumed to be able
// to send.
@@ -201,7 +218,7 @@ nni_device(nni_sock *s1, nni_sock *s2)
if ((rv = nni_aio_init(&aio, NULL, NULL)) != 0) {
return (rv);
}
- if (nni_device_init(&dd, s1, s2) != 0) {
+ if ((rv = nni_device_init(&dd, s1, s2)) != 0) {
nni_aio_fini(aio);
return (rv);
}
diff --git a/src/core/protocol.h b/src/core/protocol.h
index 01e3d11c..9b241138 100644
--- a/src/core/protocol.h
+++ b/src/core/protocol.h
@@ -127,10 +127,12 @@ struct nni_proto {
// These flags determine which operations make sense. We use them so that
// we can reject attempts to create notification fds for operations that make
-// no sense.
+// no sense. Also, we can detect raw mode, thereby providing handling for
+// that at the socket layer (NNG_PROTO_FLAG_RAW).
#define NNI_PROTO_FLAG_RCV 1 // Protocol can receive
#define NNI_PROTO_FLAG_SND 2 // Protocol can send
#define NNI_PROTO_FLAG_SNDRCV 3 // Protocol can both send & recv
+#define NNI_PROTO_FLAG_RAW 4 // Protocol is raw
// nni_proto_open is called by the protocol to create a socket instance
// with its ops vector. The intent is that applications will only see
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;