diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-04-04 12:37:34 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-04-04 13:13:24 -0700 |
| commit | 45f455064b5704f3d5ed8ecf9f197a18fe72ee59 (patch) | |
| tree | 76a626029f3a5a818b113b7e4342efaf6220a03f /src/protocol/pair0 | |
| parent | 505a9bce029e51540739c853a6c9eef0ecfb2e90 (diff) | |
| download | nng-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/protocol/pair0')
| -rw-r--r-- | src/protocol/pair0/pair.c | 37 | ||||
| -rw-r--r-- | src/protocol/pair0/pair.h | 10 |
2 files changed, 23 insertions, 24 deletions
diff --git a/src/protocol/pair0/pair.c b/src/protocol/pair0/pair.c index ccece972..e275e52c 100644 --- a/src/protocol/pair0/pair.c +++ b/src/protocol/pair0/pair.c @@ -36,7 +36,6 @@ struct pair0_sock { pair0_pipe *ppipe; nni_msgq * uwq; nni_msgq * urq; - bool raw; nni_mtx mtx; }; @@ -63,7 +62,6 @@ pair0_sock_init(void **sp, nni_sock *nsock) } nni_mtx_init(&s->mtx); s->ppipe = NULL; - s->raw = false; s->uwq = nni_sock_sendq(nsock); s->urq = nni_sock_recvq(nsock); *sp = s; @@ -231,20 +229,6 @@ pair0_sock_close(void *arg) NNI_ARG_UNUSED(arg); } -static int -pair0_sock_setopt_raw(void *arg, const void *buf, size_t sz, int typ) -{ - pair0_sock *s = arg; - return (nni_copyin_bool(&s->raw, buf, sz, typ)); -} - -static int -pair0_sock_getopt_raw(void *arg, void *buf, size_t *szp, int typ) -{ - pair0_sock *s = arg; - return (nni_copyout_bool(s->raw, buf, szp, typ)); -} - static void pair0_sock_send(void *arg, nni_aio *aio) { @@ -269,12 +253,6 @@ static nni_proto_pipe_ops pair0_pipe_ops = { }; static nni_proto_sock_option pair0_sock_options[] = { - { - .pso_name = NNG_OPT_RAW, - .pso_type = NNI_TYPE_BOOL, - .pso_getopt = pair0_sock_getopt_raw, - .pso_setopt = pair0_sock_setopt_raw, - }, // terminate list { .pso_name = NULL, @@ -301,8 +279,23 @@ static nni_proto pair0_proto = { .proto_pipe_ops = &pair0_pipe_ops, }; +static nni_proto pair0_proto_raw = { + .proto_version = NNI_PROTOCOL_VERSION, + .proto_self = { NNI_PROTO_PAIR_V0, "pair" }, + .proto_peer = { NNI_PROTO_PAIR_V0, "pair" }, + .proto_flags = NNI_PROTO_FLAG_SNDRCV | NNI_PROTO_FLAG_RAW, + .proto_sock_ops = &pair0_sock_ops, + .proto_pipe_ops = &pair0_pipe_ops, +}; + int nng_pair0_open(nng_socket *sidp) { return (nni_proto_open(sidp, &pair0_proto)); } + +int +nng_pair0_open_raw(nng_socket *sidp) +{ + return (nni_proto_open(sidp, &pair0_proto_raw)); +} diff --git a/src/protocol/pair0/pair.h b/src/protocol/pair0/pair.h index 6828c921..1356f1cd 100644 --- a/src/protocol/pair0/pair.h +++ b/src/protocol/pair0/pair.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 @@ -17,10 +17,16 @@ extern "C" { NNG_DECL int nng_pair0_open(nng_socket *); +NNG_DECL int nng_pair0_open_raw(nng_socket *); + #ifndef nng_pair_open #define nng_pair_open nng_pair0_open #endif +#ifndef nng_pair_open_raw +#define nng_pair_open_raw nng_pair0_open_raw +#endif + #ifdef __cplusplus } #endif |
