diff options
Diffstat (limited to 'src/protocol/survey0')
| -rw-r--r-- | src/protocol/survey0/respond.c | 68 | ||||
| -rw-r--r-- | src/protocol/survey0/respond.h | 9 | ||||
| -rw-r--r-- | src/protocol/survey0/survey.c | 76 | ||||
| -rw-r--r-- | src/protocol/survey0/survey.h | 9 |
4 files changed, 81 insertions, 81 deletions
diff --git a/src/protocol/survey0/respond.c b/src/protocol/survey0/respond.c index eeb09d2a..1605d9e6 100644 --- a/src/protocol/survey0/respond.c +++ b/src/protocol/survey0/respond.c @@ -40,7 +40,6 @@ static void resp0_pipe_fini(void *); struct resp0_sock { nni_msgq * urq; nni_msgq * uwq; - bool raw; int ttl; nni_idhash *pipes; char * btrace; @@ -93,7 +92,6 @@ resp0_sock_init(void **sp, nni_sock *nsock) } s->ttl = 8; // Per RFC - s->raw = false; s->btrace = NULL; s->btrace_len = 0; s->urq = nni_sock_recvq(nsock); @@ -347,36 +345,25 @@ resp0_putq_cb(void *arg) } static int -resp0_sock_setopt_raw(void *arg, const void *buf, size_t sz, int typ) +resp0_sock_setopt_maxttl(void *arg, const void *buf, size_t sz, int typ) { resp0_sock *s = arg; - int rv; - - nni_mtx_lock(&s->mtx); - rv = nni_copyin_bool(&s->raw, buf, sz, typ); - nni_mtx_unlock(&s->mtx); - return (rv); + return (nni_copyin_int(&s->ttl, buf, sz, 1, 255, typ)); } static int -resp0_sock_getopt_raw(void *arg, void *buf, size_t *szp, int typ) +resp0_sock_getopt_maxttl(void *arg, void *buf, size_t *szp, int typ) { resp0_sock *s = arg; - return (nni_copyout_bool(s->raw, buf, szp, typ)); + return (nni_copyout_int(s->ttl, buf, szp, typ)); } -static int -resp0_sock_setopt_maxttl(void *arg, const void *buf, size_t sz, int typ) +static void +resp0_sock_send_raw(void *arg, nni_aio *aio) { resp0_sock *s = arg; - return (nni_copyin_int(&s->ttl, buf, sz, 1, 255, typ)); -} -static int -resp0_sock_getopt_maxttl(void *arg, void *buf, size_t *szp, int typ) -{ - resp0_sock *s = arg; - return (nni_copyout_int(s->ttl, buf, szp, typ)); + nni_msgq_aio_put(s->uwq, aio); } static void @@ -387,11 +374,6 @@ resp0_sock_send(void *arg, nni_aio *aio) int rv; nni_mtx_lock(&s->mtx); - if (s->raw) { - nni_mtx_unlock(&s->mtx); - nni_msgq_aio_put(s->uwq, aio); - return; - } msg = nni_aio_get_msg(aio); @@ -428,10 +410,6 @@ resp0_sock_filter(void *arg, nni_msg *msg) size_t len; nni_mtx_lock(&s->mtx); - if (s->raw) { - nni_mtx_unlock(&s->mtx); - return (msg); - } len = nni_msg_header_len(msg); header = nni_msg_header(msg); @@ -469,12 +447,6 @@ static nni_proto_pipe_ops resp0_pipe_ops = { static nni_proto_sock_option resp0_sock_options[] = { { - .pso_name = NNG_OPT_RAW, - .pso_type = NNI_TYPE_BOOL, - .pso_getopt = resp0_sock_getopt_raw, - .pso_setopt = resp0_sock_setopt_raw, - }, - { .pso_name = NNG_OPT_MAXTTL, .pso_type = NNI_TYPE_INT32, .pso_getopt = resp0_sock_getopt_maxttl, @@ -497,6 +469,17 @@ static nni_proto_sock_ops resp0_sock_ops = { .sock_options = resp0_sock_options, }; +static nni_proto_sock_ops resp0_sock_ops_raw = { + .sock_init = resp0_sock_init, + .sock_fini = resp0_sock_fini, + .sock_open = resp0_sock_open, + .sock_close = resp0_sock_close, + .sock_filter = NULL, // no filter for raw + .sock_send = resp0_sock_send_raw, + .sock_recv = resp0_sock_recv, + .sock_options = resp0_sock_options, +}; + static nni_proto resp0_proto = { .proto_version = NNI_PROTOCOL_VERSION, .proto_self = { NNI_PROTO_RESPONDENT_V0, "respondent" }, @@ -506,8 +489,23 @@ static nni_proto resp0_proto = { .proto_pipe_ops = &resp0_pipe_ops, }; +static nni_proto resp0_proto_raw = { + .proto_version = NNI_PROTOCOL_VERSION, + .proto_self = { NNI_PROTO_RESPONDENT_V0, "respondent" }, + .proto_peer = { NNI_PROTO_SURVEYOR_V0, "surveyor" }, + .proto_flags = NNI_PROTO_FLAG_SNDRCV | NNI_PROTO_FLAG_RAW, + .proto_sock_ops = &resp0_sock_ops_raw, + .proto_pipe_ops = &resp0_pipe_ops, +}; + int nng_respondent0_open(nng_socket *sidp) { return (nni_proto_open(sidp, &resp0_proto)); } + +int +nng_respondent0_open_raw(nng_socket *sidp) +{ + return (nni_proto_open(sidp, &resp0_proto_raw)); +} diff --git a/src/protocol/survey0/respond.h b/src/protocol/survey0/respond.h index 58c65298..b865b2ac 100644 --- a/src/protocol/survey0/respond.h +++ b/src/protocol/survey0/respond.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 @@ -16,11 +16,16 @@ extern "C" { #endif NNG_DECL int nng_respondent0_open(nng_socket *); +NNG_DECL int nng_respondent0_open_raw(nng_socket *); #ifndef nng_respondent_open #define nng_respondent_open nng_respondent0_open #endif +#ifndef nng_respondent_open_raw +#define nng_respondent_open_raw nng_respondent0_open_raw +#endif + #ifdef __cplusplus } #endif diff --git a/src/protocol/survey0/survey.c b/src/protocol/survey0/survey.c index a5909015..b7158464 100644 --- a/src/protocol/survey0/survey.c +++ b/src/protocol/survey0/survey.c @@ -39,7 +39,6 @@ static void surv0_timeout(void *); struct surv0_sock { nni_duration survtime; nni_time expire; - bool raw; int ttl; uint32_t nextid; // next id uint32_t survid; // outstanding request ID (big endian) @@ -92,7 +91,6 @@ surv0_sock_init(void **sp, nni_sock *nsock) nni_timer_init(&s->timer, surv0_timeout, s); s->nextid = nni_random(); - s->raw = false; s->survtime = NNI_SECOND; s->expire = NNI_TIME_ZERO; s->uwq = nni_sock_sendq(nsock); @@ -275,28 +273,6 @@ failed: } static int -surv0_sock_setopt_raw(void *arg, const void *buf, size_t sz, int typ) -{ - surv0_sock *s = arg; - int rv; - - nni_mtx_lock(&s->mtx); - if ((rv = nni_copyin_bool(&s->raw, buf, sz, typ)) == 0) { - s->survid = 0; - nni_timer_cancel(&s->timer); - } - nni_mtx_unlock(&s->mtx); - return (rv); -} - -static int -surv0_sock_getopt_raw(void *arg, void *buf, size_t *szp, int typ) -{ - surv0_sock *s = arg; - return (nni_copyout_bool(s->raw, buf, szp, typ)); -} - -static int surv0_sock_setopt_maxttl(void *arg, const void *buf, size_t sz, int typ) { surv0_sock *s = arg; @@ -391,6 +367,14 @@ surv0_sock_recv(void *arg, nni_aio *aio) } static void +surv0_sock_send_raw(void *arg, nni_aio *aio) +{ + surv0_sock *s = arg; + + nni_msgq_aio_put(s->uwq, aio); +} + +static void surv0_sock_send(void *arg, nni_aio *aio) { surv0_sock *s = arg; @@ -398,13 +382,6 @@ surv0_sock_send(void *arg, nni_aio *aio) int rv; nni_mtx_lock(&s->mtx); - if (s->raw) { - // No automatic retry, and the request ID must - // be in the header coming down. - nni_mtx_unlock(&s->mtx); - nni_msgq_aio_put(s->uwq, aio); - return; - } // Generate a new request ID. We always set the high // order bit so that the peer can locate the end of the @@ -437,11 +414,6 @@ surv0_sock_filter(void *arg, nni_msg *msg) surv0_sock *s = arg; nni_mtx_lock(&s->mtx); - if (s->raw) { - // Pass it unmolested - nni_mtx_unlock(&s->mtx); - return (msg); - } if ((nni_msg_header_len(msg) < sizeof(uint32_t)) || (nni_msg_header_trim_u32(msg) != s->survid)) { @@ -464,12 +436,6 @@ static nni_proto_pipe_ops surv0_pipe_ops = { static nni_proto_sock_option surv0_sock_options[] = { { - .pso_name = NNG_OPT_RAW, - .pso_type = NNI_TYPE_BOOL, - .pso_getopt = surv0_sock_getopt_raw, - .pso_setopt = surv0_sock_setopt_raw, - }, - { .pso_name = NNG_OPT_SURVEYOR_SURVEYTIME, .pso_type = NNI_TYPE_DURATION, .pso_getopt = surv0_sock_getopt_surveytime, @@ -498,6 +464,17 @@ static nni_proto_sock_ops surv0_sock_ops = { .sock_options = surv0_sock_options, }; +static nni_proto_sock_ops surv0_sock_ops_raw = { + .sock_init = surv0_sock_init, + .sock_fini = surv0_sock_fini, + .sock_open = surv0_sock_open, + .sock_close = surv0_sock_close, + .sock_send = surv0_sock_send_raw, + .sock_recv = surv0_sock_recv, + .sock_filter = surv0_sock_filter, + .sock_options = surv0_sock_options, +}; + static nni_proto surv0_proto = { .proto_version = NNI_PROTOCOL_VERSION, .proto_self = { NNI_PROTO_SURVEYOR_V0, "surveyor" }, @@ -507,8 +484,23 @@ static nni_proto surv0_proto = { .proto_pipe_ops = &surv0_pipe_ops, }; +static nni_proto surv0_proto_raw = { + .proto_version = NNI_PROTOCOL_VERSION, + .proto_self = { NNI_PROTO_SURVEYOR_V0, "surveyor" }, + .proto_peer = { NNI_PROTO_RESPONDENT_V0, "respondent" }, + .proto_flags = NNI_PROTO_FLAG_SNDRCV | NNI_PROTO_FLAG_RAW, + .proto_sock_ops = &surv0_sock_ops_raw, + .proto_pipe_ops = &surv0_pipe_ops, +}; + int nng_surveyor0_open(nng_socket *sidp) { return (nni_proto_open(sidp, &surv0_proto)); } + +int +nng_surveyor0_open_raw(nng_socket *sidp) +{ + return (nni_proto_open(sidp, &surv0_proto_raw)); +} diff --git a/src/protocol/survey0/survey.h b/src/protocol/survey0/survey.h index a7b6d943..37f76fbf 100644 --- a/src/protocol/survey0/survey.h +++ b/src/protocol/survey0/survey.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 @@ -16,11 +16,16 @@ extern "C" { #endif NNG_DECL int nng_surveyor0_open(nng_socket *); +NNG_DECL int nng_surveyor0_open_raw(nng_socket *); #ifndef nng_surveyor_open #define nng_surveyor_open nng_surveyor0_open #endif +#ifndef nng_surveyor_open_raw +#define nng_surveyor_open_raw nng_surveyor0_open_raw +#endif + #define NNG_OPT_SURVEYOR_SURVEYTIME "surveyor:survey-time" #ifdef __cplusplus |
