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/device.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/core/device.c') 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); } -- cgit v1.2.3-70-g09d2