aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nng_compat.c3
-rw-r--r--src/nng_compat.h3
-rw-r--r--tests/CMakeLists.txt4
-rw-r--r--tests/compat_iovec.c73
-rw-r--r--tests/compat_pair.c49
-rw-r--r--tests/compat_pipeline.c80
-rw-r--r--tests/compat_survey.c105
7 files changed, 315 insertions, 2 deletions
diff --git a/src/nng_compat.c b/src/nng_compat.c
index 9515dc31..160fd33d 100644
--- a/src/nng_compat.c
+++ b/src/nng_compat.c
@@ -622,7 +622,7 @@ nn_setsockopt(int s, int nnlevel, int nnopt, const void *valp, size_t sz)
break;
case NN_SURVEYOR:
switch (nnopt) {
- case NN_SURVEY_DEADLINE:
+ case NN_SURVEYOR_DEADLINE:
opt = NNG_OPT_SURVEYTIME;
mscvt = 1;
break;
@@ -630,6 +630,7 @@ nn_setsockopt(int s, int nnlevel, int nnopt, const void *valp, size_t sz)
errno = ENOPROTOOPT;
return (-1);
}
+ break;
default:
errno = ENOPROTOOPT;
return (-1);
diff --git a/src/nng_compat.h b/src/nng_compat.h
index cd189b2d..e83c20b8 100644
--- a/src/nng_compat.h
+++ b/src/nng_compat.h
@@ -1,5 +1,6 @@
//
// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// Copyright 2017 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -218,7 +219,7 @@ extern "C" {
#define NN_SUB_SUBSCRIBE (NN_SUB * 16 + 1)
#define NN_SUB_UNSUBSCRIBE (NN_SUB * 16 + 2)
#define NN_REQ_RESEND_IVL (NN_REQ * 16 + 1)
-#define NN_SURVEY_DEADLINE (NN_SURVEYOR * 16 + 1)
+#define NN_SURVEYOR_DEADLINE (NN_SURVEYOR * 16 + 1)
// Level options for tranports
#define NN_INPROC (-1)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 47c086d2..7b8768dc 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -94,5 +94,9 @@ add_nng_compat_test(compat_bug777 5)
add_nng_compat_test(compat_bus 5)
add_nng_compat_test(compat_cmsg 5)
add_nng_compat_test(compat_msg 5)
+add_nng_compat_test(compat_iovec 5)
add_nng_compat_test(compat_device 5)
+add_nng_compat_test(compat_pair 5)
+add_nng_compat_test(compat_pipeline 5)
add_nng_compat_test(compat_reqrep 5)
+add_nng_compat_test(compat_survey 5)
diff --git a/tests/compat_iovec.c b/tests/compat_iovec.c
new file mode 100644
index 00000000..44cb5deb
--- /dev/null
+++ b/tests/compat_iovec.c
@@ -0,0 +1,73 @@
+/*
+ Copyright (c) 2013 Martin Sustrik All rights reserved.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom
+ the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ IN THE SOFTWARE.
+*/
+
+#include "nng_compat.h"
+
+#include "compat_testutil.h"
+
+#include <string.h>
+
+#define SOCKET_ADDRESS "inproc://a"
+
+int main ()
+{
+ int rc;
+ int sb;
+ int sc;
+ struct nn_iovec iov [2];
+ struct nn_msghdr hdr;
+ char buf [6];
+
+ sb = test_socket (AF_SP, NN_PAIR);
+ test_bind (sb, SOCKET_ADDRESS);
+ sc = test_socket (AF_SP, NN_PAIR);
+ test_connect (sc, SOCKET_ADDRESS);
+
+ iov [0].iov_base = "AB";
+ iov [0].iov_len = 2;
+ iov [1].iov_base = "CDEF";
+ iov [1].iov_len = 4;
+ memset (&hdr, 0, sizeof (hdr));
+ hdr.msg_iov = iov;
+ hdr.msg_iovlen = 2;
+ rc = nn_sendmsg (sc, &hdr, 0);
+ errno_assert (rc >= 0);
+ nn_assert (rc == 6);
+
+ iov [0].iov_base = buf;
+ iov [0].iov_len = 4;
+ iov [1].iov_base = buf + 4;
+ iov [1].iov_len = 2;
+ memset (&hdr, 0, sizeof (hdr));
+ hdr.msg_iov = iov;
+ hdr.msg_iovlen = 2;
+ rc = nn_recvmsg (sb, &hdr, 0);
+ errno_assert (rc >= 0);
+ nn_assert (rc == 6);
+ nn_assert (memcmp (buf, "ABCDEF", 6) == 0);
+
+ test_close (sc);
+ test_close (sb);
+
+ return 0;
+}
+
diff --git a/tests/compat_pair.c b/tests/compat_pair.c
new file mode 100644
index 00000000..d12e135e
--- /dev/null
+++ b/tests/compat_pair.c
@@ -0,0 +1,49 @@
+/*
+ Copyright (c) 2012 Martin Sustrik All rights reserved.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom
+ the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ IN THE SOFTWARE.
+*/
+
+#include "nng_compat.h"
+
+#include "compat_testutil.h"
+
+#define SOCKET_ADDRESS "inproc://a"
+
+int main ()
+{
+ int sb;
+ int sc;
+
+ sb = test_socket (AF_SP, NN_PAIR);
+ test_bind (sb, SOCKET_ADDRESS);
+ sc = test_socket (AF_SP, NN_PAIR);
+ test_connect (sc, SOCKET_ADDRESS);
+
+ test_send (sc, "ABC");
+ test_recv (sb, "ABC");
+ test_send (sb, "DEF");
+ test_recv (sc, "DEF");
+
+ test_close (sc);
+ test_close (sb);
+
+ return 0;
+}
+
diff --git a/tests/compat_pipeline.c b/tests/compat_pipeline.c
new file mode 100644
index 00000000..3587097f
--- /dev/null
+++ b/tests/compat_pipeline.c
@@ -0,0 +1,80 @@
+/*
+ Copyright (c) 2012 Martin Sustrik All rights reserved.
+ Copyright (c) 2013 GoPivotal, Inc. All rights reserved.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom
+ the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ IN THE SOFTWARE.
+*/
+
+#include "nng_compat.h"
+#include "compat_testutil.h"
+
+#define SOCKET_ADDRESS "inproc://a"
+
+int main ()
+{
+ int push1;
+ int push2;
+ int pull1;
+ int pull2;
+
+ /* Test fan-out. */
+
+ push1 = test_socket (AF_SP, NN_PUSH);
+ test_bind (push1, SOCKET_ADDRESS);
+ pull1 = test_socket (AF_SP, NN_PULL);
+ test_connect (pull1, SOCKET_ADDRESS);
+ pull2 = test_socket (AF_SP, NN_PULL);
+ test_connect (pull2, SOCKET_ADDRESS);
+
+ /* Wait till both connections are established to get messages spread
+ evenly between the two pull sockets. */
+ nn_sleep (10);
+
+ test_send (push1, "ABC");
+ test_send (push1, "DEF");
+
+ test_recv (pull1, "ABC");
+ test_recv (pull2, "DEF");
+
+ test_close (push1);
+ test_close (pull1);
+ test_close (pull2);
+
+ /* Test fan-in. */
+
+ pull1 = test_socket (AF_SP, NN_PULL);
+ test_bind (pull1, SOCKET_ADDRESS);
+ push1 = test_socket (AF_SP, NN_PUSH);
+ test_connect (push1, SOCKET_ADDRESS);
+ push2 = test_socket (AF_SP, NN_PUSH);
+ test_connect (push2, SOCKET_ADDRESS);
+
+ test_send (push1, "ABC");
+ test_send (push2, "DEF");
+
+ test_recv (pull1, "ABC");
+ test_recv (pull1, "DEF");
+
+ test_close (pull1);
+ test_close (push1);
+ test_close (push2);
+
+ return 0;
+}
+
diff --git a/tests/compat_survey.c b/tests/compat_survey.c
new file mode 100644
index 00000000..fc5f8091
--- /dev/null
+++ b/tests/compat_survey.c
@@ -0,0 +1,105 @@
+/*
+ Copyright (c) 2012 Martin Sustrik All rights reserved.
+ Copyright 2017 Garrett D'Amore
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom
+ the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#include "nng_compat.h"
+
+#include "compat_testutil.h"
+
+#define SOCKET_ADDRESS "inproc://test"
+
+int
+main()
+{
+ int rc;
+ int surveyor;
+ int respondent1;
+ int respondent2;
+ int respondent3;
+ int deadline;
+ char buf[7];
+
+ /* Test a simple survey with three respondents. */
+ surveyor = test_socket(AF_SP, NN_SURVEYOR);
+ deadline = 500;
+ rc = nn_setsockopt(surveyor, NN_SURVEYOR, NN_SURVEYOR_DEADLINE,
+ &deadline, sizeof(deadline));
+ errno_assert(rc == 0);
+ test_bind(surveyor, SOCKET_ADDRESS);
+ respondent1 = test_socket(AF_SP, NN_RESPONDENT);
+ test_connect(respondent1, SOCKET_ADDRESS);
+ respondent2 = test_socket(AF_SP, NN_RESPONDENT);
+ test_connect(respondent2, SOCKET_ADDRESS);
+ respondent3 = test_socket(AF_SP, NN_RESPONDENT);
+ test_connect(respondent3, SOCKET_ADDRESS);
+
+ /* Sleep a tiny bit. */
+ nn_sleep(1000);
+
+ /* Check that attempt to recv with no survey pending is EFSM. */
+ rc = nn_recv(surveyor, buf, sizeof(buf), 0);
+ errno_assert(rc == -1 && nn_errno() == EFSM);
+
+ /* Send the survey. */
+ test_send(surveyor, "ABC");
+
+ /* First respondent answers. */
+ test_recv(respondent1, "ABC");
+ test_send(respondent1, "DEF");
+
+ /* Second respondent answers. */
+ test_recv(respondent2, "ABC");
+ test_send(respondent2, "DEF");
+
+ /* Surveyor gets the responses. */
+ test_recv(surveyor, "DEF");
+ test_recv(surveyor, "DEF");
+
+ /* There are no more responses. Surveyor hits the deadline. */
+ rc = nn_recv(surveyor, buf, sizeof(buf), 0);
+ errno_assert(rc == -1 && nn_errno() == ETIMEDOUT);
+
+ /* Third respondent answers (it have already missed the deadline). */
+ test_recv(respondent3, "ABC");
+ test_send(respondent3, "GHI");
+
+ /* Surveyor initiates new survey. */
+ test_send(surveyor, "ABC");
+
+ /* Check that stale response from third respondent is not delivered.
+ */
+ rc = nn_recv(surveyor, buf, sizeof(buf), 0);
+ errno_assert(rc == -1 && nn_errno() == ETIMEDOUT);
+
+ /* Check that subsequent attempt to recv with no survey pending is
+ * EFSM. */
+ nn_sleep(1000); // nng - sleep a bit as there may be a thread race
+ rc = nn_recv(surveyor, buf, sizeof(buf), 0);
+ errno_assert(rc == -1 && nn_errno() == EFSM);
+
+ test_close(surveyor);
+ test_close(respondent1);
+ test_close(respondent2);
+ test_close(respondent3);
+
+ return 0;
+}