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/reqrep0/rep.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/reqrep0/rep.c')
| -rw-r--r-- | src/protocol/reqrep0/rep.c | 70 |
1 files changed, 33 insertions, 37 deletions
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); @@ -353,25 +351,6 @@ rep0_pipe_putq_cb(void *arg) } 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) { rep0_sock *s = arg; @@ -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); @@ -417,6 +392,13 @@ rep0_sock_filter(void *arg, nni_msg *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) { rep0_sock *s = arg; @@ -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); @@ -475,12 +451,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, .pso_getopt = rep0_sock_getopt_maxttl, @@ -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)); +} |
