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/pair1/pair.c | |
| 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/pair1/pair.c')
| -rw-r--r-- | src/protocol/pair1/pair.c | 65 |
1 files changed, 39 insertions, 26 deletions
diff --git a/src/protocol/pair1/pair.c b/src/protocol/pair1/pair.c index becbbfa7..a3c01d46 100644 --- a/src/protocol/pair1/pair.c +++ b/src/protocol/pair1/pair.c @@ -72,7 +72,7 @@ pair1_sock_fini(void *arg) } static int -pair1_sock_init(void **sp, nni_sock *nsock) +pair1_sock_init_impl(void **sp, nni_sock *nsock, bool raw) { pair1_sock *s; int rv; @@ -94,7 +94,7 @@ pair1_sock_init(void **sp, nni_sock *nsock) return (rv); } - s->raw = false; + s->raw = raw; s->poly = false; s->uwq = nni_sock_sendq(nsock); s->urq = nni_sock_recvq(nsock); @@ -104,6 +104,18 @@ pair1_sock_init(void **sp, nni_sock *nsock) return (0); } +static int +pair1_sock_init(void **sp, nni_sock *nsock) +{ + return (pair1_sock_init_impl(sp, nsock, false)); +} + +static int +pair1_sock_init_raw(void **sp, nni_sock *nsock) +{ + return (pair1_sock_init_impl(sp, nsock, true)); +} + static void pair1_pipe_fini(void *arg) { @@ -397,24 +409,6 @@ pair1_sock_close(void *arg) } static int -pair1_sock_setopt_raw(void *arg, const void *buf, size_t sz, int typ) -{ - pair1_sock *s = arg; - int rv; - nni_mtx_lock(&s->mtx); - rv = s->started ? NNG_ESTATE : nni_copyin_bool(&s->raw, buf, sz, typ); - nni_mtx_unlock(&s->mtx); - return (rv); -} - -static int -pair1_sock_getopt_raw(void *arg, void *buf, size_t *szp, int typ) -{ - pair1_sock *s = arg; - return (nni_copyout_bool(s->raw, buf, szp, typ)); -} - -static int pair1_sock_setopt_maxttl(void *arg, const void *buf, size_t sz, int typ) { pair1_sock *s = arg; @@ -475,12 +469,6 @@ static nni_proto_pipe_ops pair1_pipe_ops = { static nni_proto_sock_option pair1_sock_options[] = { { - .pso_name = NNG_OPT_RAW, - .pso_type = NNI_TYPE_BOOL, - .pso_getopt = pair1_sock_getopt_raw, - .pso_setopt = pair1_sock_setopt_raw, - }, - { .pso_name = NNG_OPT_MAXTTL, .pso_type = NNI_TYPE_INT32, .pso_getopt = pair1_sock_getopt_maxttl, @@ -522,3 +510,28 @@ nng_pair1_open(nng_socket *sidp) { return (nni_proto_open(sidp, &pair1_proto)); } + +static nni_proto_sock_ops pair1_sock_ops_raw = { + .sock_init = pair1_sock_init_raw, + .sock_fini = pair1_sock_fini, + .sock_open = pair1_sock_open, + .sock_close = pair1_sock_close, + .sock_recv = pair1_sock_recv, + .sock_send = pair1_sock_send, + .sock_options = pair1_sock_options, +}; + +static nni_proto pair1_proto_raw = { + .proto_version = NNI_PROTOCOL_VERSION, + .proto_self = { NNI_PROTO_PAIR_V1, "pair1" }, + .proto_peer = { NNI_PROTO_PAIR_V1, "pair1" }, + .proto_flags = NNI_PROTO_FLAG_SNDRCV | NNI_PROTO_FLAG_RAW, + .proto_sock_ops = &pair1_sock_ops_raw, + .proto_pipe_ops = &pair1_pipe_ops, +}; + +int +nng_pair1_open_raw(nng_socket *sidp) +{ + return (nni_proto_open(sidp, &pair1_proto_raw)); +} |
