diff options
| author | Garrett D'Amore <garrett@damore.org> | 2020-01-20 23:31:55 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2020-01-20 23:35:08 -0800 |
| commit | 38c005e7c07b5ccaab3345dc8c66cbc27b95692a (patch) | |
| tree | 7d35c74df9f0f320942e6c8c601e963a4cc11741 /src/protocol/survey0/survey.c | |
| parent | 058ad941dc55ad6288f6b07f4cdf237fd13f1a93 (diff) | |
| download | nng-38c005e7c07b5ccaab3345dc8c66cbc27b95692a.tar.gz nng-38c005e7c07b5ccaab3345dc8c66cbc27b95692a.tar.bz2 nng-38c005e7c07b5ccaab3345dc8c66cbc27b95692a.zip | |
fixes #1169 survey and xsurvey could use message cloning
fixes #1160 Consider limiting maximum hop count to 15
fixes #1098 Maximum maxTTL should be compile time defined
This doesn't expose the max-MaxTTL in the CMakeList.txt -- there
is really no reason anyone should be changing it. This does not
yet inline the message header into the nni_msg_t, but it is my
intention to do so soon, and eliminate most of the conditional cases
for failure on inserting into the header.
Diffstat (limited to 'src/protocol/survey0/survey.c')
| -rw-r--r-- | src/protocol/survey0/survey.c | 44 |
1 files changed, 13 insertions, 31 deletions
diff --git a/src/protocol/survey0/survey.c b/src/protocol/survey0/survey.c index 9746ff45..dcf92e07 100644 --- a/src/protocol/survey0/survey.c +++ b/src/protocol/survey0/survey.c @@ -39,11 +39,11 @@ struct surv0_ctx { // surv0_sock is our per-socket protocol private structure. struct surv0_sock { - int ttl; - nni_list pipes; - nni_mtx mtx; - surv0_ctx ctx; - nni_idhash * surveys; + int ttl; + nni_list pipes; + nni_mtx mtx; + surv0_ctx ctx; + nni_idhash * surveys; nni_pollable writable; }; @@ -161,34 +161,18 @@ surv0_ctx_send(void *arg, nni_aio *aio) nni_aio_finish_error(aio, rv); return; } - // Insert it into the message. We report an error if one occurs, - // although arguably at this point we could just discard silently. - if ((rv = nni_msg_header_append_u32(msg, (uint32_t) ctx->survid)) != - 0) { - nni_idhash_remove(sock->surveys, ctx->survid); - ctx->survid = 0; - nni_mtx_unlock(&sock->mtx); - nni_aio_finish_error(aio, rv); - return; - } + nni_msg_header_clear(msg); + nni_msg_header_must_append_u32(msg, (uint32_t) ctx->survid); // From this point, we're committed to success. Note that we send // regardless of whether there are any pipes or not. If no pipes, // then it just gets discarded. nni_aio_set_msg(aio, NULL); NNI_LIST_FOREACH (&sock->pipes, pipe) { - nni_msg *dmsg; - - if (nni_list_next(&sock->pipes, pipe) != NULL) { - if (nni_msg_dup(&dmsg, msg) != 0) { - continue; - } - } else { - dmsg = msg; - msg = NULL; - } - if (nni_msgq_tryput(pipe->sendq, dmsg) != 0) { - nni_msg_free(dmsg); + + nni_msg_clone(msg); + if (nni_msgq_tryput(pipe->sendq, msg) != 0) { + nni_msg_free(msg); } } @@ -199,9 +183,7 @@ surv0_ctx_send(void *arg, nni_aio *aio) nni_msgq_set_get_error(ctx->rq, 0); nni_mtx_unlock(&sock->mtx); - if (msg != NULL) { - nni_msg_free(msg); - } + nni_msg_free(msg); nni_aio_finish(aio, 0, len); } @@ -441,7 +423,7 @@ static int surv0_sock_set_maxttl(void *arg, const void *buf, size_t sz, nni_opt_type t) { surv0_sock *s = arg; - return (nni_copyin_int(&s->ttl, buf, sz, 1, 255, t)); + return (nni_copyin_int(&s->ttl, buf, sz, 1, NNI_MAX_MAX_TTL, t)); } static int |
