aboutsummaryrefslogtreecommitdiff
path: root/src/protocol/reqrep0
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocol/reqrep0')
-rw-r--r--src/protocol/reqrep0/rep_test.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/protocol/reqrep0/rep_test.c b/src/protocol/reqrep0/rep_test.c
index 324176a0..a79a342b 100644
--- a/src/protocol/reqrep0/rep_test.c
+++ b/src/protocol/reqrep0/rep_test.c
@@ -12,6 +12,7 @@
#include <nng/nng.h>
#include <nng/protocol/reqrep0/rep.h>
#include <nng/protocol/reqrep0/req.h>
+#include <nng/supplemental/util/platform.h>
#include <acutest.h>
#include <testutil.h>
@@ -430,6 +431,63 @@ test_rep_close_recv(void)
nng_aio_free(aio);
}
+struct rep_close_recv_cb_state {
+ nng_aio *aio;
+ nng_mtx *mtx;
+ nng_cv * cv;
+ int done;
+ int result;
+ nng_msg *msg;
+};
+
+static void
+rep_close_recv_cb(void *arg)
+{
+ struct rep_close_recv_cb_state *state = arg;
+
+ nng_mtx_lock(state->mtx);
+ state->result = nng_aio_result(state->aio);
+ state->msg = nng_aio_get_msg(state->aio);
+ state->done = true;
+ nng_cv_wake(state->cv);
+ nng_mtx_unlock(state->mtx);
+}
+
+void
+test_rep_close_recv_cb(void)
+{
+ nng_socket rep;
+ nng_socket req;
+ struct rep_close_recv_cb_state state;
+
+ memset(&state, 0, sizeof(state));
+ TEST_NNG_PASS(nng_mtx_alloc(&state.mtx));
+ TEST_NNG_PASS(nng_cv_alloc(&state.cv, state.mtx));
+
+ TEST_NNG_PASS(nng_rep0_open(&rep));
+ TEST_NNG_PASS(nng_req0_open_raw(&req));
+ TEST_NNG_PASS(nng_setopt_ms(rep, NNG_OPT_RECVTIMEO, 1000));
+ TEST_NNG_PASS(nng_setopt_ms(rep, NNG_OPT_SENDTIMEO, 1000));
+ TEST_NNG_PASS(nng_setopt_ms(req, NNG_OPT_SENDTIMEO, 1000));
+
+ TEST_NNG_PASS(testutil_marry(req, rep));
+ TEST_NNG_PASS(nng_aio_alloc(&state.aio, rep_close_recv_cb, &state));
+ nng_recv_aio(rep, state.aio);
+ TEST_NNG_PASS(nng_close(rep));
+ TEST_NNG_PASS(nng_close(req));
+ nng_mtx_lock(state.mtx);
+ while (!state.done) {
+ TEST_NNG_PASS(nng_cv_until(state.cv, nng_clock() + 1000));
+ }
+ nng_mtx_unlock(state.mtx);
+ TEST_CHECK(state.done != 0);
+ TEST_NNG_FAIL(nng_aio_result(state.aio), NNG_ECLOSED);
+ TEST_CHECK(nng_aio_get_msg(state.aio) == NULL);
+ nng_aio_free(state.aio);
+ nng_cv_free(state.cv);
+ nng_mtx_free(state.mtx);
+}
+
static void
test_rep_ctx_recv_nonblock(void)
{
@@ -617,6 +675,7 @@ TEST_LIST = {
{ "rep close pipe context send", test_rep_close_pipe_context_send },
{ "rep close context send", test_rep_close_context_send },
{ "rep close recv", test_rep_close_recv },
+ { "rep close recv cb", test_rep_close_recv_cb },
{ "rep context send nonblock", test_rep_ctx_send_nonblock },
{ "rep context send nonblock 2", test_rep_ctx_send_nonblock2 },
{ "rep context recv nonblock", test_rep_ctx_recv_nonblock },