From fdefff742662ed4eb476bf19b9dda245f86bc406 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 20 Apr 2018 20:52:32 -0700 Subject: fixes #342 Want Surveyor/Respondent context support fixes #360 core should nng_aio_begin before nng_aio_finish_error fixes #361 nng_send_aio should check for NULL message fixes #362 nni_msgq does not signal pollable on certain events This adds support for contexts for both sides of the surveyor pattern. Prior to this commit, the raw mode was completely broken, and there were numerous other bugs found and fixed. This integration includes *much* deeper validation of this pattern. Some changes to the core and other patterns have been made, where it was obvioius that we could make such improvements. (The obviousness stemming from the fact that RESPONDENT in particular is very closely derived from REP.) --- src/nng.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/nng.c') diff --git a/src/nng.c b/src/nng.c index 9eb33f50..fb374dde 100644 --- a/src/nng.c +++ b/src/nng.c @@ -198,7 +198,9 @@ nng_recv_aio(nng_socket sid, nng_aio *aio) int rv; if ((rv = nni_sock_find(&sock, sid)) != 0) { - nni_aio_finish_error(aio, rv); + if (nni_aio_begin(aio) == 0) { + nni_aio_finish_error(aio, rv); + } return; } nni_sock_recv(sock, aio); @@ -211,8 +213,16 @@ nng_send_aio(nng_socket sid, nng_aio *aio) nni_sock *sock; int rv; + if (nni_aio_get_msg(aio) == NULL) { + if (nni_aio_begin(aio) == 0) { + nni_aio_finish_error(aio, NNG_EINVAL); + } + return; + } if ((rv = nni_sock_find(&sock, sid)) != 0) { - nni_aio_finish_error(aio, rv); + if (nni_aio_begin(aio) == 0) { + nni_aio_finish_error(aio, rv); + } return; } nni_sock_send(sock, aio); @@ -260,7 +270,9 @@ nng_ctx_recv(nng_ctx cid, nng_aio *aio) nni_ctx *ctx; if ((rv = nni_ctx_find(&ctx, cid, false)) != 0) { - nni_aio_finish_error(aio, rv); + if (nni_aio_begin(aio) == 0) { + nni_aio_finish_error(aio, rv); + } return; } nni_ctx_recv(ctx, aio); @@ -273,8 +285,16 @@ nng_ctx_send(nng_ctx cid, nng_aio *aio) int rv; nni_ctx *ctx; + if (nni_aio_get_msg(aio) == NULL) { + if (nni_aio_begin(aio) == 0) { + nni_aio_finish_error(aio, NNG_EINVAL); + } + return; + } if ((rv = nni_ctx_find(&ctx, cid, false)) != 0) { - nni_aio_finish_error(aio, rv); + if (nni_aio_begin(aio) == 0) { + nni_aio_finish_error(aio, rv); + } return; } nni_ctx_send(ctx, aio); -- cgit v1.2.3-70-g09d2