aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/testutil.c19
-rw-r--r--tests/testutil.h6
2 files changed, 22 insertions, 3 deletions
diff --git a/tests/testutil.c b/tests/testutil.c
index 36999448..356eb333 100644
--- a/tests/testutil.c
+++ b/tests/testutil.c
@@ -1,5 +1,5 @@
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 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
@@ -303,20 +303,23 @@ struct marriage_notice {
int s2;
int cnt1;
int cnt2;
+ nng_pipe p1;
+ nng_pipe p2;
};
static void
married(nng_pipe p, nng_pipe_ev ev, void *arg)
{
struct marriage_notice *notice = arg;
- (void) p;
(void) ev;
nng_mtx_lock(notice->mx);
if (nng_socket_id(nng_pipe_socket(p)) == notice->s1) {
notice->cnt1++;
+ notice->p1 = p;
} else if (nng_socket_id(nng_pipe_socket(p)) == notice->s2) {
notice->cnt2++;
+ notice->p2 = p;
}
nng_cv_wake(notice->cv);
nng_mtx_unlock(notice->mx);
@@ -325,6 +328,12 @@ married(nng_pipe p, nng_pipe_ev ev, void *arg)
int
testutil_marry(nng_socket s1, nng_socket s2)
{
+ return (testutil_marry_ex(s1, s2, NULL, NULL));
+}
+
+int
+testutil_marry_ex(nng_socket s1, nng_socket s2, nng_pipe *p1, nng_pipe *p2)
+{
struct marriage_notice note;
nng_time timeout;
int rv;
@@ -357,6 +366,12 @@ testutil_marry(nng_socket s1, nng_socket s2)
}
}
nng_mtx_unlock(note.mx);
+ if (p1 != NULL) {
+ *p1 = note.p1;
+ }
+ if (p2 != NULL) {
+ *p2 = note.p2;
+ }
done:
nng_pipe_notify(s1, NNG_PIPE_EV_ADD_POST, NULL, NULL);
diff --git a/tests/testutil.h b/tests/testutil.h
index 008c8061..16e665f2 100644
--- a/tests/testutil.h
+++ b/tests/testutil.h
@@ -1,5 +1,5 @@
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -50,6 +50,10 @@ extern void testutil_scratch_addr(const char *, size_t, char *);
// are fully connected.
extern int testutil_marry(nng_socket, nng_socket);
+// testutil_marry_ex is like testutil_marry, but returns the pipes that
+// were connected. The pipe pointers may be NULL if not needed.
+extern int testutil_marry_ex(nng_socket, nng_socket, nng_pipe *, nng_pipe *);
+
// TEST_NNG_PASS tests for NNG success. It reports the failure if it
// did not.
#define TEST_NNG_PASS(cond) \