aboutsummaryrefslogtreecommitdiff
path: root/src/sp/protocol/survey0
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-12-26 10:20:33 -0800
committerGarrett D'Amore <garrett@damore.org>2024-12-26 10:52:17 -0800
commit06ebeefb102b223ff77dd47e16b64bd9575f7c34 (patch)
treecf5d70cadfd2f7261bb5fd6443d2c449d1c1e812 /src/sp/protocol/survey0
parentd02a320cffc82de8437c28869355a403069b3b21 (diff)
downloadnng-06ebeefb102b223ff77dd47e16b64bd9575f7c34.tar.gz
nng-06ebeefb102b223ff77dd47e16b64bd9575f7c34.tar.bz2
nng-06ebeefb102b223ff77dd47e16b64bd9575f7c34.zip
aio: introduce NNG_ESTOPPED
This error code results when an AIO is stopped permanently, as a result of nni_aio_close or nni_aio_stop. The associated AIO object cannot be used again. This discrimantes against a file being closed, or a temporary cancellation which might allow the aio to be reused. Consumers must check for this error status in their callbacks, and not resubmit an operation that failed with this error. Doing so, will result in an infinite loop of submit / errors.
Diffstat (limited to 'src/sp/protocol/survey0')
-rw-r--r--src/sp/protocol/survey0/respond_test.c21
-rw-r--r--src/sp/protocol/survey0/xrespond_test.c18
-rw-r--r--src/sp/protocol/survey0/xsurvey_test.c2
3 files changed, 40 insertions, 1 deletions
diff --git a/src/sp/protocol/survey0/respond_test.c b/src/sp/protocol/survey0/respond_test.c
index 0260dc30..ad8f7e60 100644
--- a/src/sp/protocol/survey0/respond_test.c
+++ b/src/sp/protocol/survey0/respond_test.c
@@ -257,6 +257,26 @@ test_resp_ctx_recv_aio_stopped(void)
nng_aio_stop(aio);
nng_ctx_recv(ctx, aio);
nng_aio_wait(aio);
+ NUTS_FAIL(nng_aio_result(aio), NNG_ESTOPPED);
+ NUTS_PASS(nng_ctx_close(ctx));
+ NUTS_CLOSE(resp);
+ nng_aio_free(aio);
+}
+
+void
+test_resp_ctx_recv_aio_canceled(void)
+{
+ nng_socket resp;
+ nng_ctx ctx;
+ nng_aio *aio;
+
+ NUTS_PASS(nng_respondent0_open(&resp));
+ NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
+ NUTS_PASS(nng_ctx_open(&ctx, resp));
+
+ nng_ctx_recv(ctx, aio);
+ nng_aio_cancel(aio);
+ nng_aio_wait(aio);
NUTS_FAIL(nng_aio_result(aio), NNG_ECANCELED);
NUTS_PASS(nng_ctx_close(ctx));
NUTS_CLOSE(resp);
@@ -548,6 +568,7 @@ TEST_LIST = {
{ "respond close pipe before send", test_resp_close_pipe_before_send },
{ "respond close pipe during send", test_resp_close_pipe_during_send },
{ "respond recv aio ctx stopped", test_resp_ctx_recv_aio_stopped },
+ { "respond recv aio ctx canceled", test_resp_ctx_recv_aio_canceled },
{ "respond close pipe context send",
test_resp_close_pipe_context_send },
{ "respond close context send", test_resp_close_context_send },
diff --git a/src/sp/protocol/survey0/xrespond_test.c b/src/sp/protocol/survey0/xrespond_test.c
index 8106f161..579438ec 100644
--- a/src/sp/protocol/survey0/xrespond_test.c
+++ b/src/sp/protocol/survey0/xrespond_test.c
@@ -262,6 +262,23 @@ test_xresp_recv_aio_stopped(void)
nng_aio_stop(aio);
nng_recv_aio(resp, aio);
nng_aio_wait(aio);
+ NUTS_FAIL(nng_aio_result(aio), NNG_ESTOPPED);
+ NUTS_CLOSE(resp);
+ nng_aio_free(aio);
+}
+
+static void
+test_xresp_recv_aio_canceled(void)
+{
+ nng_socket resp;
+ nng_aio *aio;
+
+ NUTS_PASS(nng_respondent0_open_raw(&resp));
+ NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));
+
+ nng_recv_aio(resp, aio);
+ nng_aio_cancel(aio);
+ nng_aio_wait(aio);
NUTS_FAIL(nng_aio_result(aio), NNG_ECANCELED);
NUTS_CLOSE(resp);
nng_aio_free(aio);
@@ -418,6 +435,7 @@ NUTS_TESTS = {
test_xresp_close_pipe_during_send },
{ "xrespond close during recv", test_xresp_close_during_recv },
{ "xrespond recv aio stopped", test_xresp_recv_aio_stopped },
+ { "xrespond recv aio canceled", test_xresp_recv_aio_canceled },
{ "xrespond send no header", test_xresp_send_no_header },
{ "xrespond recv garbage", test_xresp_recv_garbage },
{ "xrespond ttl option", test_xresp_ttl_option },
diff --git a/src/sp/protocol/survey0/xsurvey_test.c b/src/sp/protocol/survey0/xsurvey_test.c
index e90939e9..b151f230 100644
--- a/src/sp/protocol/survey0/xsurvey_test.c
+++ b/src/sp/protocol/survey0/xsurvey_test.c
@@ -167,7 +167,7 @@ test_xsurvey_recv_aio_stopped(void)
nng_aio_stop(aio);
nng_recv_aio(surv, aio);
nng_aio_wait(aio);
- NUTS_FAIL(nng_aio_result(aio), NNG_ECANCELED);
+ NUTS_FAIL(nng_aio_result(aio), NNG_ESTOPPED);
NUTS_CLOSE(surv);
nng_aio_free(aio);
}