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/protocol/reqrep0/rep.c | 70 ++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 37 deletions(-) (limited to 'src/protocol/reqrep0/rep.c') diff --git a/src/protocol/reqrep0/rep.c b/src/protocol/reqrep0/rep.c index f62406cd..78a1f2ee 100644 --- a/src/protocol/reqrep0/rep.c +++ b/src/protocol/reqrep0/rep.c @@ -41,7 +41,6 @@ struct rep0_sock { nni_msgq * uwq; nni_msgq * urq; nni_mtx lk; - bool raw; int ttl; nni_idhash *pipes; char * btrace; @@ -92,7 +91,6 @@ rep0_sock_init(void **sp, nni_sock *sock) } s->ttl = 8; // Per RFC - s->raw = false; s->btrace = NULL; s->btrace_len = 0; s->uwq = nni_sock_sendq(sock); @@ -352,25 +350,6 @@ rep0_pipe_putq_cb(void *arg) nni_pipe_recv(p->pipe, p->aio_recv); } -static int -rep0_sock_setopt_raw(void *arg, const void *buf, size_t sz, int typ) -{ - rep0_sock *s = arg; - int rv; - - nni_mtx_lock(&s->lk); - rv = nni_copyin_bool(&s->raw, buf, sz, typ); - nni_mtx_unlock(&s->lk); - return (rv); -} - -static int -rep0_sock_getopt_raw(void *arg, void *buf, size_t *szp, int typ) -{ - rep0_sock *s = arg; - return (nni_copyout_bool(s->raw, buf, szp, typ)); -} - static int rep0_sock_setopt_maxttl(void *arg, const void *buf, size_t sz, int typ) { @@ -393,10 +372,6 @@ rep0_sock_filter(void *arg, nni_msg *msg) size_t len; nni_mtx_lock(&s->lk); - if (s->raw) { - nni_mtx_unlock(&s->lk); - return (msg); - } len = nni_msg_header_len(msg); header = nni_msg_header(msg); @@ -416,6 +391,13 @@ rep0_sock_filter(void *arg, nni_msg *msg) return (msg); } +static void +rep0_sock_send_raw(void *arg, nni_aio *aio) +{ + rep0_sock *s = arg; + nni_msgq_aio_put(s->uwq, aio); +} + static void rep0_sock_send(void *arg, nni_aio *aio) { @@ -424,12 +406,6 @@ rep0_sock_send(void *arg, nni_aio *aio) nni_msg * msg; nni_mtx_lock(&s->lk); - if (s->raw) { - // Pass thru - nni_mtx_unlock(&s->lk); - nni_msgq_aio_put(s->uwq, aio); - return; - } if (s->btrace == NULL) { nni_mtx_unlock(&s->lk); nni_aio_finish_error(aio, NNG_ESTATE); @@ -474,12 +450,6 @@ static nni_proto_pipe_ops rep0_pipe_ops = { }; static nni_proto_sock_option rep0_sock_options[] = { - { - .pso_name = NNG_OPT_RAW, - .pso_type = NNI_TYPE_BOOL, - .pso_getopt = rep0_sock_getopt_raw, - .pso_setopt = rep0_sock_setopt_raw, - }, { .pso_name = NNG_OPT_MAXTTL, .pso_type = NNI_TYPE_INT32, @@ -503,6 +473,17 @@ static nni_proto_sock_ops rep0_sock_ops = { .sock_recv = rep0_sock_recv, }; +static nni_proto_sock_ops rep0_sock_ops_raw = { + .sock_init = rep0_sock_init, + .sock_fini = rep0_sock_fini, + .sock_open = rep0_sock_open, + .sock_close = rep0_sock_close, + .sock_options = rep0_sock_options, + .sock_filter = NULL, // No filtering for raw mode + .sock_send = rep0_sock_send_raw, + .sock_recv = rep0_sock_recv, +}; + static nni_proto rep0_proto = { .proto_version = NNI_PROTOCOL_VERSION, .proto_self = { NNI_PROTO_REP_V0, "rep" }, @@ -512,8 +493,23 @@ static nni_proto rep0_proto = { .proto_pipe_ops = &rep0_pipe_ops, }; +static nni_proto rep0_proto_raw = { + .proto_version = NNI_PROTOCOL_VERSION, + .proto_self = { NNI_PROTO_REP_V0, "rep" }, + .proto_peer = { NNI_PROTO_REQ_V0, "req" }, + .proto_flags = NNI_PROTO_FLAG_SNDRCV | NNI_PROTO_FLAG_RAW, + .proto_sock_ops = &rep0_sock_ops_raw, + .proto_pipe_ops = &rep0_pipe_ops, +}; + int nng_rep0_open(nng_socket *sidp) { return (nni_proto_open(sidp, &rep0_proto)); } + +int +nng_rep0_open_raw(nng_socket *sidp) +{ + return (nni_proto_open(sidp, &rep0_proto_raw)); +} -- cgit v1.2.3-70-g09d2