mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-26 23:01:04 +08:00
Problem: tests do not follow naming style
Solution: apply naming style
This commit is contained in:
parent
d767909b50
commit
779d120fa3
@ -46,10 +46,10 @@ void test__zmq_z85_encode__valid__success ()
|
||||
}
|
||||
|
||||
// Buffer length must be evenly divisible by 4 or must fail with EINVAL.
|
||||
void test__zmq_z85_encode__invalid__failure (size_t size)
|
||||
void test__zmq_z85_encode__invalid__failure (size_t size_)
|
||||
{
|
||||
errno = 0;
|
||||
assert (zmq_z85_encode (NULL, NULL, size) == NULL);
|
||||
assert (zmq_z85_encode (NULL, NULL, size_) == NULL);
|
||||
assert (zmq_errno () == EINVAL);
|
||||
}
|
||||
|
||||
@ -70,11 +70,11 @@ void test__zmq_z85_decode__valid__success ()
|
||||
|
||||
// Invalid input data must fail with EINVAL.
|
||||
template <size_t SIZE>
|
||||
void test__zmq_z85_decode__invalid__failure (const char (&encoded)[SIZE])
|
||||
void test__zmq_z85_decode__invalid__failure (const char (&encoded_)[SIZE])
|
||||
{
|
||||
uint8_t decoded[SIZE * 4 / 5 + 1];
|
||||
errno = 0;
|
||||
assert (zmq_z85_decode (decoded, encoded) == NULL);
|
||||
assert (zmq_z85_decode (decoded, encoded_) == NULL);
|
||||
assert (zmq_errno () == EINVAL);
|
||||
}
|
||||
|
||||
@ -82,28 +82,28 @@ void test__zmq_z85_decode__invalid__failure (const char (&encoded)[SIZE])
|
||||
// call zmq_z85_encode, then zmq_z85_decode, and compare the results with the original
|
||||
template <size_t SIZE>
|
||||
void test__zmq_z85_encode__zmq_z85_decode__roundtrip (
|
||||
const uint8_t (&test_data)[SIZE])
|
||||
const uint8_t (&test_data_)[SIZE])
|
||||
{
|
||||
char test_data_z85[SIZE * 5 / 4 + 1];
|
||||
char *res1 = zmq_z85_encode (test_data_z85, test_data, SIZE);
|
||||
char *res1 = zmq_z85_encode (test_data_z85, test_data_, SIZE);
|
||||
assert (res1 != NULL);
|
||||
|
||||
uint8_t test_data_decoded[SIZE];
|
||||
uint8_t *res2 = zmq_z85_decode (test_data_decoded, test_data_z85);
|
||||
assert (res2 != NULL);
|
||||
|
||||
int res3 = memcmp (test_data, test_data_decoded, SIZE);
|
||||
int res3 = memcmp (test_data_, test_data_decoded, SIZE);
|
||||
assert (res3 == 0);
|
||||
}
|
||||
|
||||
// call zmq_z85_encode, then zmq_z85_decode, and compare the results with the original
|
||||
template <size_t SIZE>
|
||||
void test__zmq_z85_decode__zmq_z85_encode__roundtrip (
|
||||
const char (&test_data)[SIZE])
|
||||
const char (&test_data_)[SIZE])
|
||||
{
|
||||
const size_t decoded_size = (SIZE - 1) * 4 / 5;
|
||||
uint8_t test_data_decoded[decoded_size];
|
||||
uint8_t *res1 = zmq_z85_decode (test_data_decoded, test_data);
|
||||
uint8_t *res1 = zmq_z85_decode (test_data_decoded, test_data_);
|
||||
assert (res1 != NULL);
|
||||
|
||||
char test_data_z85[SIZE];
|
||||
@ -111,7 +111,7 @@ void test__zmq_z85_decode__zmq_z85_encode__roundtrip (
|
||||
zmq_z85_encode (test_data_z85, test_data_decoded, decoded_size);
|
||||
assert (res2 != NULL);
|
||||
|
||||
int res3 = memcmp (test_data, test_data_z85, SIZE);
|
||||
int res3 = memcmp (test_data_, test_data_z85, SIZE);
|
||||
assert (res3 == 0);
|
||||
}
|
||||
|
||||
|
@ -42,20 +42,20 @@ void tearDown ()
|
||||
teardown_test_context ();
|
||||
}
|
||||
|
||||
void create_inproc_client_server_pair (void **server, void **client)
|
||||
void create_inproc_client_server_pair (void **server_, void **client_)
|
||||
{
|
||||
*server = test_context_socket (ZMQ_SERVER);
|
||||
*client = test_context_socket (ZMQ_CLIENT);
|
||||
*server_ = test_context_socket (ZMQ_SERVER);
|
||||
*client_ = test_context_socket (ZMQ_CLIENT);
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_bind (*server, "inproc://test-client-server"));
|
||||
zmq_bind (*server_, "inproc://test-client-server"));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_connect (*client, "inproc://test-client-server"));
|
||||
zmq_connect (*client_, "inproc://test-client-server"));
|
||||
}
|
||||
|
||||
void send_sndmore_expect_failure (void *socket)
|
||||
void send_sndmore_expect_failure (void *socket_)
|
||||
{
|
||||
int rc = zmq_send (socket, "X", 1, ZMQ_SNDMORE);
|
||||
int rc = zmq_send (socket_, "X", 1, ZMQ_SNDMORE);
|
||||
TEST_ASSERT_EQUAL_INT (-1, rc);
|
||||
TEST_ASSERT_EQUAL_INT (EINVAL, errno);
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ void test_stream_2_stream ()
|
||||
zmq_ctx_destroy (ctx);
|
||||
}
|
||||
|
||||
void test_router_2_router (bool named)
|
||||
void test_router_2_router (bool named_)
|
||||
{
|
||||
void *rbind, *rconn1;
|
||||
int ret;
|
||||
@ -128,7 +128,7 @@ void test_router_2_router (bool named)
|
||||
assert (0 == ret);
|
||||
|
||||
// If we're in named mode, set some identities.
|
||||
if (named) {
|
||||
if (named_) {
|
||||
ret = zmq_setsockopt (rbind, ZMQ_ROUTING_ID, "X", 1);
|
||||
ret = zmq_setsockopt (rconn1, ZMQ_ROUTING_ID, "Y", 1);
|
||||
}
|
||||
@ -153,7 +153,7 @@ void test_router_2_router (bool named)
|
||||
|
||||
// Receive the name.
|
||||
ret = zmq_recv (rbind, buff, 256, 0);
|
||||
if (named)
|
||||
if (named_)
|
||||
assert (ret && 'Y' == buff[0]);
|
||||
else
|
||||
assert (ret && 0 == buff[0]);
|
||||
@ -163,7 +163,7 @@ void test_router_2_router (bool named)
|
||||
assert (5 == ret && 'h' == buff[128]);
|
||||
|
||||
// Send some data back.
|
||||
if (named) {
|
||||
if (named_) {
|
||||
ret = zmq_send (rbind, buff, 1, ZMQ_SNDMORE);
|
||||
assert (1 == ret);
|
||||
} else {
|
||||
|
@ -40,10 +40,10 @@ void tearDown ()
|
||||
{
|
||||
}
|
||||
|
||||
static void receiver (void *socket)
|
||||
static void receiver (void *socket_)
|
||||
{
|
||||
char buffer[16];
|
||||
int rc = zmq_recv (socket, &buffer, sizeof (buffer), 0);
|
||||
int rc = zmq_recv (socket_, &buffer, sizeof (buffer), 0);
|
||||
assert (rc == -1);
|
||||
}
|
||||
|
||||
@ -147,12 +147,12 @@ void run_poller (void *data_)
|
||||
}
|
||||
#endif
|
||||
|
||||
void test_poller_exists_with_socket_on_zmq_ctx_term (const int socket_type)
|
||||
void test_poller_exists_with_socket_on_zmq_ctx_term (const int socket_type_)
|
||||
{
|
||||
#ifdef ZMQ_HAVE_POLLER
|
||||
struct poller_test_data_t poller_test_data;
|
||||
|
||||
poller_test_data.socket_type = socket_type;
|
||||
poller_test_data.socket_type = socket_type_;
|
||||
|
||||
// Set up our context and sockets
|
||||
poller_test_data.ctx = zmq_ctx_new ();
|
||||
|
@ -74,15 +74,15 @@ bool is_allowed_to_raise_priority ()
|
||||
#endif
|
||||
|
||||
|
||||
void test_ctx_thread_opts (void *ctx)
|
||||
void test_ctx_thread_opts (void *ctx_)
|
||||
{
|
||||
int rc;
|
||||
|
||||
// verify that setting negative values (e.g., default values) fail:
|
||||
rc =
|
||||
zmq_ctx_set (ctx, ZMQ_THREAD_SCHED_POLICY, ZMQ_THREAD_SCHED_POLICY_DFLT);
|
||||
zmq_ctx_set (ctx_, ZMQ_THREAD_SCHED_POLICY, ZMQ_THREAD_SCHED_POLICY_DFLT);
|
||||
assert (rc == -1 && errno == EINVAL);
|
||||
rc = zmq_ctx_set (ctx, ZMQ_THREAD_PRIORITY, ZMQ_THREAD_PRIORITY_DFLT);
|
||||
rc = zmq_ctx_set (ctx_, ZMQ_THREAD_PRIORITY, ZMQ_THREAD_PRIORITY_DFLT);
|
||||
assert (rc == -1 && errno == EINVAL);
|
||||
|
||||
|
||||
@ -90,7 +90,7 @@ void test_ctx_thread_opts (void *ctx)
|
||||
|
||||
// set context options that alter the background thread CPU scheduling/affinity settings;
|
||||
// as of ZMQ 4.2.3 this has an effect only on POSIX systems (nothing happens on Windows, but still it should return success):
|
||||
rc = zmq_ctx_set (ctx, ZMQ_THREAD_SCHED_POLICY, TEST_POLICY);
|
||||
rc = zmq_ctx_set (ctx_, ZMQ_THREAD_SCHED_POLICY, TEST_POLICY);
|
||||
assert (rc == 0);
|
||||
|
||||
|
||||
@ -107,7 +107,7 @@ void test_ctx_thread_opts (void *ctx)
|
||||
// check that the current effective user is able to do that:
|
||||
if (is_allowed_to_raise_priority ()) {
|
||||
rc = zmq_ctx_set (
|
||||
ctx, ZMQ_THREAD_PRIORITY,
|
||||
ctx_, ZMQ_THREAD_PRIORITY,
|
||||
1 /* any positive value different than the default will be ok */);
|
||||
assert (rc == 0);
|
||||
}
|
||||
@ -123,7 +123,7 @@ void test_ctx_thread_opts (void *ctx)
|
||||
int cpus_add[] = {0, 1};
|
||||
for (unsigned int idx = 0; idx < sizeof (cpus_add) / sizeof (cpus_add[0]);
|
||||
idx++) {
|
||||
rc = zmq_ctx_set (ctx, ZMQ_THREAD_AFFINITY_CPU_ADD, cpus_add[idx]);
|
||||
rc = zmq_ctx_set (ctx_, ZMQ_THREAD_AFFINITY_CPU_ADD, cpus_add[idx]);
|
||||
assert (rc == 0);
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ void test_ctx_thread_opts (void *ctx)
|
||||
for (unsigned int idx = 0;
|
||||
idx < sizeof (cpus_remove) / sizeof (cpus_remove[0]); idx++) {
|
||||
rc =
|
||||
zmq_ctx_set (ctx, ZMQ_THREAD_AFFINITY_CPU_REMOVE, cpus_remove[idx]);
|
||||
zmq_ctx_set (ctx_, ZMQ_THREAD_AFFINITY_CPU_REMOVE, cpus_remove[idx]);
|
||||
assert (rc == 0);
|
||||
}
|
||||
#endif
|
||||
@ -141,30 +141,30 @@ void test_ctx_thread_opts (void *ctx)
|
||||
#ifdef ZMQ_THREAD_NAME_PREFIX
|
||||
// test thread name prefix:
|
||||
|
||||
rc = zmq_ctx_set (ctx, ZMQ_THREAD_NAME_PREFIX, 1234);
|
||||
rc = zmq_ctx_set (ctx_, ZMQ_THREAD_NAME_PREFIX, 1234);
|
||||
assert (rc == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_ctx_zero_copy (void *ctx)
|
||||
void test_ctx_zero_copy (void *ctx_)
|
||||
{
|
||||
#ifdef ZMQ_ZERO_COPY_RECV
|
||||
int zero_copy;
|
||||
// Default value is 1.
|
||||
zero_copy = zmq_ctx_get (ctx, ZMQ_ZERO_COPY_RECV);
|
||||
zero_copy = zmq_ctx_get (ctx_, ZMQ_ZERO_COPY_RECV);
|
||||
assert (zero_copy == 1);
|
||||
|
||||
// Test we can set it to 0.
|
||||
assert (0 == zmq_ctx_set (ctx, ZMQ_ZERO_COPY_RECV, 0));
|
||||
zero_copy = zmq_ctx_get (ctx, ZMQ_ZERO_COPY_RECV);
|
||||
assert (0 == zmq_ctx_set (ctx_, ZMQ_ZERO_COPY_RECV, 0));
|
||||
zero_copy = zmq_ctx_get (ctx_, ZMQ_ZERO_COPY_RECV);
|
||||
assert (zero_copy == 0);
|
||||
|
||||
// Create a TCP socket pair using the context and test that messages can be
|
||||
// received. Note that inproc sockets cannot be used for this test.
|
||||
void *pull = zmq_socket (ctx, ZMQ_PULL);
|
||||
void *pull = zmq_socket (ctx_, ZMQ_PULL);
|
||||
assert (0 == zmq_bind (pull, "tcp://127.0.0.1:*"));
|
||||
|
||||
void *push = zmq_socket (ctx, ZMQ_PUSH);
|
||||
void *push = zmq_socket (ctx_, ZMQ_PUSH);
|
||||
size_t endpoint_len = MAX_SOCKET_STRING;
|
||||
char endpoint[MAX_SOCKET_STRING];
|
||||
assert (
|
||||
@ -191,8 +191,8 @@ void test_ctx_zero_copy (void *ctx)
|
||||
assert (0 == zmq_close (pull));
|
||||
assert (0 == zmq_msg_close (&small_msg));
|
||||
assert (0 == zmq_msg_close (&large_msg));
|
||||
assert (0 == zmq_ctx_set (ctx, ZMQ_ZERO_COPY_RECV, 1));
|
||||
zero_copy = zmq_ctx_get (ctx, ZMQ_ZERO_COPY_RECV);
|
||||
assert (0 == zmq_ctx_set (ctx_, ZMQ_ZERO_COPY_RECV, 1));
|
||||
zero_copy = zmq_ctx_get (ctx_, ZMQ_ZERO_COPY_RECV);
|
||||
assert (zero_copy == 1);
|
||||
#endif
|
||||
}
|
||||
|
@ -49,17 +49,17 @@ int main (int, char **)
|
||||
{
|
||||
setup_test_environment ();
|
||||
void *context = zmq_ctx_new ();
|
||||
void *pubSocket;
|
||||
void *subSocket;
|
||||
void *pub_socket;
|
||||
void *sub_socket;
|
||||
|
||||
(pubSocket = zmq_socket (context, ZMQ_XPUB))
|
||||
(pub_socket = zmq_socket (context, ZMQ_XPUB))
|
||||
|| printf ("zmq_socket: %s\n", zmq_strerror (errno));
|
||||
(subSocket = zmq_socket (context, ZMQ_SUB))
|
||||
(sub_socket = zmq_socket (context, ZMQ_SUB))
|
||||
|| printf ("zmq_socket: %s\n", zmq_strerror (errno));
|
||||
zmq_setsockopt (subSocket, ZMQ_SUBSCRIBE, "foo", 3)
|
||||
zmq_setsockopt (sub_socket, ZMQ_SUBSCRIBE, "foo", 3)
|
||||
&& printf ("zmq_setsockopt: %s\n", zmq_strerror (errno));
|
||||
|
||||
zmq_bind (pubSocket, "inproc://someInProcDescriptor")
|
||||
zmq_bind (pub_socket, "inproc://someInProcDescriptor")
|
||||
&& printf ("zmq_bind: %s\n", zmq_strerror (errno));
|
||||
//zmq_bind(pubSocket, "tcp://127.0.0.1:30010") && printf("zmq_bind: %s\n", zmq_strerror(errno));
|
||||
|
||||
@ -69,8 +69,8 @@ int main (int, char **)
|
||||
|
||||
while (1) {
|
||||
zmq_pollitem_t items[] = {
|
||||
{subSocket, 0, ZMQ_POLLIN, 0}, // read publications
|
||||
{pubSocket, 0, ZMQ_POLLIN, 0}, // read subscriptions
|
||||
{sub_socket, 0, ZMQ_POLLIN, 0}, // read publications
|
||||
{pub_socket, 0, ZMQ_POLLIN, 0}, // read subscriptions
|
||||
};
|
||||
int rc = zmq_poll (items, 2, 100);
|
||||
|
||||
@ -78,7 +78,7 @@ int main (int, char **)
|
||||
while (1) {
|
||||
zmq_msg_t msg;
|
||||
zmq_msg_init (&msg);
|
||||
zmq_msg_recv (&msg, pubSocket, 0);
|
||||
zmq_msg_recv (&msg, pub_socket, 0);
|
||||
char *buffer = (char *) zmq_msg_data (&msg);
|
||||
|
||||
if (buffer[0] == 0) {
|
||||
@ -89,7 +89,7 @@ int main (int, char **)
|
||||
isSubscribed = true;
|
||||
}
|
||||
|
||||
zmq_getsockopt (pubSocket, ZMQ_RCVMORE, &more, &more_size);
|
||||
zmq_getsockopt (pub_socket, ZMQ_RCVMORE, &more, &more_size);
|
||||
zmq_msg_close (&msg);
|
||||
|
||||
if (!more)
|
||||
@ -101,8 +101,8 @@ int main (int, char **)
|
||||
while (1) {
|
||||
zmq_msg_t msg;
|
||||
zmq_msg_init (&msg);
|
||||
zmq_msg_recv (&msg, subSocket, 0);
|
||||
zmq_getsockopt (subSocket, ZMQ_RCVMORE, &more, &more_size);
|
||||
zmq_msg_recv (&msg, sub_socket, 0);
|
||||
zmq_getsockopt (sub_socket, ZMQ_RCVMORE, &more, &more_size);
|
||||
zmq_msg_close (&msg);
|
||||
|
||||
if (!more) {
|
||||
@ -112,28 +112,28 @@ int main (int, char **)
|
||||
}
|
||||
}
|
||||
if (iteration == 1) {
|
||||
zmq_connect (subSocket, "inproc://someInProcDescriptor")
|
||||
zmq_connect (sub_socket, "inproc://someInProcDescriptor")
|
||||
&& printf ("zmq_connect: %s\n", zmq_strerror (errno));
|
||||
msleep (SETTLE_TIME);
|
||||
}
|
||||
if (iteration == 4) {
|
||||
zmq_disconnect (subSocket, "inproc://someInProcDescriptor")
|
||||
zmq_disconnect (sub_socket, "inproc://someInProcDescriptor")
|
||||
&& printf ("zmq_disconnect(%d): %s\n", errno,
|
||||
zmq_strerror (errno));
|
||||
}
|
||||
if (iteration > 4 && rc == 0)
|
||||
break;
|
||||
|
||||
zmq_msg_t channelEnvlp;
|
||||
ZMQ_PREPARE_STRING (channelEnvlp, "foo", 3);
|
||||
zmq_msg_send (&channelEnvlp, pubSocket, ZMQ_SNDMORE) >= 0
|
||||
zmq_msg_t channel_envlp;
|
||||
ZMQ_PREPARE_STRING (channel_envlp, "foo", 3);
|
||||
zmq_msg_send (&channel_envlp, pub_socket, ZMQ_SNDMORE) >= 0
|
||||
|| printf ("zmq_msg_send: %s\n", zmq_strerror (errno));
|
||||
zmq_msg_close (&channelEnvlp)
|
||||
zmq_msg_close (&channel_envlp)
|
||||
&& printf ("zmq_msg_close: %s\n", zmq_strerror (errno));
|
||||
|
||||
zmq_msg_t message;
|
||||
ZMQ_PREPARE_STRING (message, "this is foo!", 12);
|
||||
zmq_msg_send (&message, pubSocket, 0) >= 0
|
||||
zmq_msg_send (&message, pub_socket, 0) >= 0
|
||||
|| printf ("zmq_msg_send: %s\n", zmq_strerror (errno));
|
||||
zmq_msg_close (&message)
|
||||
&& printf ("zmq_msg_close: %s\n", zmq_strerror (errno));
|
||||
@ -143,8 +143,8 @@ int main (int, char **)
|
||||
assert (publicationsReceived == 3);
|
||||
assert (!isSubscribed);
|
||||
|
||||
zmq_close (pubSocket) && printf ("zmq_close: %s", zmq_strerror (errno));
|
||||
zmq_close (subSocket) && printf ("zmq_close: %s", zmq_strerror (errno));
|
||||
zmq_close (pub_socket) && printf ("zmq_close: %s", zmq_strerror (errno));
|
||||
zmq_close (sub_socket) && printf ("zmq_close: %s", zmq_strerror (errno));
|
||||
|
||||
zmq_ctx_term (context);
|
||||
return 0;
|
||||
|
@ -29,35 +29,36 @@
|
||||
|
||||
#include "testutil.hpp"
|
||||
|
||||
static void bounce_fail (void *server, void *client)
|
||||
static void bounce_fail (void *server_, void *client_)
|
||||
{
|
||||
const char *content = "12345678ABCDEFGH12345678abcdefgh";
|
||||
char buffer[32];
|
||||
|
||||
// Send message from client to server
|
||||
int rc = zmq_send (client, content, 32, ZMQ_SNDMORE);
|
||||
int rc = zmq_send (client_, content, 32, ZMQ_SNDMORE);
|
||||
assert (rc == 32);
|
||||
rc = zmq_send (client, content, 32, 0);
|
||||
rc = zmq_send (client_, content, 32, 0);
|
||||
assert (rc == 32);
|
||||
|
||||
// Receive message at server side (should not succeed)
|
||||
int timeout = 250;
|
||||
rc = zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof (int));
|
||||
rc = zmq_setsockopt (server_, ZMQ_RCVTIMEO, &timeout, sizeof (int));
|
||||
assert (rc == 0);
|
||||
rc = zmq_recv (server, buffer, 32, 0);
|
||||
rc = zmq_recv (server_, buffer, 32, 0);
|
||||
assert (rc == -1);
|
||||
assert (zmq_errno () == EAGAIN);
|
||||
|
||||
// Send message from server to client to test other direction
|
||||
rc = zmq_setsockopt (server, ZMQ_SNDTIMEO, &timeout, sizeof (int));
|
||||
rc = zmq_setsockopt (server_, ZMQ_SNDTIMEO, &timeout, sizeof (int));
|
||||
assert (rc == 0);
|
||||
rc = zmq_send (server, content, 32, ZMQ_SNDMORE);
|
||||
rc = zmq_send (server_, content, 32, ZMQ_SNDMORE);
|
||||
assert (rc == -1);
|
||||
assert (zmq_errno () == EAGAIN);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static void run_test (int opt, T optval, int expected_error, int bounce_test)
|
||||
static void
|
||||
run_test (int opt_, T optval_, int expected_error_, int bounce_test_)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@ -67,11 +68,11 @@ static void run_test (int opt, T optval, int expected_error, int bounce_test)
|
||||
void *sb = zmq_socket (ctx, ZMQ_DEALER);
|
||||
assert (sb);
|
||||
|
||||
if (opt) {
|
||||
rc = zmq_setsockopt (sb, opt, &optval, sizeof (optval));
|
||||
if (expected_error) {
|
||||
if (opt_) {
|
||||
rc = zmq_setsockopt (sb, opt_, &optval_, sizeof (optval_));
|
||||
if (expected_error_) {
|
||||
assert (rc == -1);
|
||||
assert (zmq_errno () == expected_error);
|
||||
assert (zmq_errno () == expected_error_);
|
||||
} else
|
||||
assert (rc == 0);
|
||||
}
|
||||
@ -93,7 +94,7 @@ static void run_test (int opt, T optval, int expected_error, int bounce_test)
|
||||
rc = zmq_setsockopt (sc, ZMQ_RECONNECT_IVL, &interval, sizeof (int));
|
||||
assert (rc == 0);
|
||||
|
||||
if (bounce_test) {
|
||||
if (bounce_test_) {
|
||||
const char *endpoint = "ipc://test_filter_ipc.sock";
|
||||
int rc = zmq_bind (sb, endpoint);
|
||||
assert (rc == 0);
|
||||
@ -101,7 +102,7 @@ static void run_test (int opt, T optval, int expected_error, int bounce_test)
|
||||
rc = zmq_connect (sc, endpoint);
|
||||
assert (rc == 0);
|
||||
|
||||
if (bounce_test > 0)
|
||||
if (bounce_test_ > 0)
|
||||
bounce (sb, sc);
|
||||
else
|
||||
bounce_fail (sb, sc);
|
||||
|
@ -54,13 +54,13 @@ void tearDown ()
|
||||
// by reference, if not null, and event number by value. Returns -1
|
||||
// in case of error.
|
||||
|
||||
static int get_monitor_event (void *monitor)
|
||||
static int get_monitor_event (void *monitor_)
|
||||
{
|
||||
for (int i = 0; i < 2; i++) {
|
||||
// First frame in message contains event number and value
|
||||
zmq_msg_t msg;
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg));
|
||||
if (zmq_msg_recv (&msg, monitor, ZMQ_DONTWAIT) == -1) {
|
||||
if (zmq_msg_recv (&msg, monitor_, ZMQ_DONTWAIT) == -1) {
|
||||
msleep (SETTLE_TIME);
|
||||
continue; // Interrupted, presumably
|
||||
}
|
||||
@ -71,7 +71,7 @@ static int get_monitor_event (void *monitor)
|
||||
|
||||
// Second frame in message contains event address
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg));
|
||||
if (zmq_msg_recv (&msg, monitor, 0) == -1) {
|
||||
if (zmq_msg_recv (&msg, monitor_, 0) == -1) {
|
||||
return -1; // Interrupted, presumably
|
||||
}
|
||||
TEST_ASSERT_FALSE (zmq_msg_more (&msg));
|
||||
@ -81,21 +81,21 @@ static int get_monitor_event (void *monitor)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void recv_with_retry (raw_socket fd, char *buffer, int bytes)
|
||||
static void recv_with_retry (raw_socket fd_, char *buffer_, int bytes_)
|
||||
{
|
||||
int received = 0;
|
||||
while (true) {
|
||||
int rc = TEST_ASSERT_SUCCESS_RAW_ERRNO (
|
||||
recv (fd, buffer + received, bytes - received, 0));
|
||||
recv (fd_, buffer_ + received, bytes_ - received, 0));
|
||||
TEST_ASSERT_GREATER_THAN_INT (0, rc);
|
||||
received += rc;
|
||||
TEST_ASSERT_LESS_OR_EQUAL_INT (bytes, received);
|
||||
if (received == bytes)
|
||||
TEST_ASSERT_LESS_OR_EQUAL_INT (bytes_, received);
|
||||
if (received == bytes_)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void mock_handshake (raw_socket fd, int mock_ping)
|
||||
static void mock_handshake (raw_socket fd_, int mock_ping_)
|
||||
{
|
||||
const uint8_t zmtp_greeting[33] = {0xff, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0x7f, 3, 0, 'N', 'U', 'L', 'L', 0};
|
||||
@ -103,10 +103,10 @@ static void mock_handshake (raw_socket fd, int mock_ping)
|
||||
memset (buffer, 0, sizeof (buffer));
|
||||
memcpy (buffer, zmtp_greeting, sizeof (zmtp_greeting));
|
||||
|
||||
int rc = TEST_ASSERT_SUCCESS_RAW_ERRNO (send (fd, buffer, 64, 0));
|
||||
int rc = TEST_ASSERT_SUCCESS_RAW_ERRNO (send (fd_, buffer, 64, 0));
|
||||
TEST_ASSERT_EQUAL_INT (64, rc);
|
||||
|
||||
recv_with_retry (fd, buffer, 64);
|
||||
recv_with_retry (fd_, buffer, 64);
|
||||
|
||||
const uint8_t zmtp_ready[43] = {
|
||||
4, 41, 5, 'R', 'E', 'A', 'D', 'Y', 11, 'S', 'o', 'c', 'k', 'e', 't',
|
||||
@ -115,13 +115,13 @@ static void mock_handshake (raw_socket fd, int mock_ping)
|
||||
|
||||
memset (buffer, 0, sizeof (buffer));
|
||||
memcpy (buffer, zmtp_ready, 43);
|
||||
rc = TEST_ASSERT_SUCCESS_RAW_ERRNO (send (fd, buffer, 43, 0));
|
||||
rc = TEST_ASSERT_SUCCESS_RAW_ERRNO (send (fd_, buffer, 43, 0));
|
||||
TEST_ASSERT_EQUAL_INT (43, rc);
|
||||
|
||||
// greeting
|
||||
recv_with_retry (fd, buffer, 43);
|
||||
recv_with_retry (fd_, buffer, 43);
|
||||
|
||||
if (mock_ping) {
|
||||
if (mock_ping_) {
|
||||
// test PING context - should be replicated in the PONG
|
||||
// to avoid timeouts, do a bulk send
|
||||
const uint8_t zmtp_ping[12] = {4, 10, 4, 'P', 'I', 'N',
|
||||
@ -129,7 +129,7 @@ static void mock_handshake (raw_socket fd, int mock_ping)
|
||||
uint8_t zmtp_pong[10] = {4, 8, 4, 'P', 'O', 'N', 'G', 'L', 'O', 'L'};
|
||||
memset (buffer, 0, sizeof (buffer));
|
||||
memcpy (buffer, zmtp_ping, 12);
|
||||
rc = TEST_ASSERT_SUCCESS_RAW_ERRNO (send (fd, buffer, 12, 0));
|
||||
rc = TEST_ASSERT_SUCCESS_RAW_ERRNO (send (fd_, buffer, 12, 0));
|
||||
TEST_ASSERT_EQUAL_INT (12, rc);
|
||||
|
||||
// test a larger body that won't fit in a small message and should get
|
||||
@ -137,27 +137,27 @@ static void mock_handshake (raw_socket fd, int mock_ping)
|
||||
memset (buffer, 'z', sizeof (buffer));
|
||||
memcpy (buffer, zmtp_ping, 12);
|
||||
buffer[1] = 65;
|
||||
rc = TEST_ASSERT_SUCCESS_RAW_ERRNO (send (fd, buffer, 67, 0));
|
||||
rc = TEST_ASSERT_SUCCESS_RAW_ERRNO (send (fd_, buffer, 67, 0));
|
||||
TEST_ASSERT_EQUAL_INT (67, rc);
|
||||
|
||||
// small pong
|
||||
recv_with_retry (fd, buffer, 10);
|
||||
recv_with_retry (fd_, buffer, 10);
|
||||
TEST_ASSERT_EQUAL_INT (0, memcmp (zmtp_pong, buffer, 10));
|
||||
// large pong
|
||||
recv_with_retry (fd, buffer, 23);
|
||||
recv_with_retry (fd_, buffer, 23);
|
||||
uint8_t zmtp_pooong[65] = {4, 21, 4, 'P', 'O', 'N', 'G', 'L', 'O', 'L'};
|
||||
memset (zmtp_pooong + 10, 'z', 55);
|
||||
TEST_ASSERT_EQUAL_INT (0, memcmp (zmtp_pooong, buffer, 23));
|
||||
}
|
||||
}
|
||||
|
||||
static void setup_curve (void *socket, int is_server)
|
||||
static void setup_curve (void *socket_, int is_server_)
|
||||
{
|
||||
const char *secret_key;
|
||||
const char *public_key;
|
||||
const char *server_key;
|
||||
|
||||
if (is_server) {
|
||||
if (is_server_) {
|
||||
secret_key = "JTKVSB%%)wK0E.X)V>+}o?pNmC{O&4W4b!Ni{Lh6";
|
||||
public_key = "rq:rM>}U?@Lns47E1%kR.o@n%FcmmsL/@{H8]yf7";
|
||||
server_key = NULL;
|
||||
@ -167,43 +167,43 @@ static void setup_curve (void *socket, int is_server)
|
||||
server_key = "rq:rM>}U?@Lns47E1%kR.o@n%FcmmsL/@{H8]yf7";
|
||||
}
|
||||
|
||||
zmq_setsockopt (socket, ZMQ_CURVE_SECRETKEY, secret_key,
|
||||
zmq_setsockopt (socket_, ZMQ_CURVE_SECRETKEY, secret_key,
|
||||
strlen (secret_key));
|
||||
zmq_setsockopt (socket, ZMQ_CURVE_PUBLICKEY, public_key,
|
||||
zmq_setsockopt (socket_, ZMQ_CURVE_PUBLICKEY, public_key,
|
||||
strlen (public_key));
|
||||
if (is_server)
|
||||
zmq_setsockopt (socket, ZMQ_CURVE_SERVER, &is_server,
|
||||
sizeof (is_server));
|
||||
if (is_server_)
|
||||
zmq_setsockopt (socket_, ZMQ_CURVE_SERVER, &is_server_,
|
||||
sizeof (is_server_));
|
||||
else
|
||||
zmq_setsockopt (socket, ZMQ_CURVE_SERVERKEY, server_key,
|
||||
zmq_setsockopt (socket_, ZMQ_CURVE_SERVERKEY, server_key,
|
||||
strlen (server_key));
|
||||
}
|
||||
|
||||
static void prep_server_socket (int set_heartbeats,
|
||||
int is_curve,
|
||||
void **server_out,
|
||||
void **mon_out,
|
||||
char *endpoint,
|
||||
size_t ep_length,
|
||||
int socket_type)
|
||||
static void prep_server_socket (int set_heartbeats_,
|
||||
int is_curve_,
|
||||
void **server_out_,
|
||||
void **mon_out_,
|
||||
char *endpoint_,
|
||||
size_t ep_length_,
|
||||
int socket_type_)
|
||||
{
|
||||
// We'll be using this socket in raw mode
|
||||
void *server = test_context_socket (socket_type);
|
||||
void *server = test_context_socket (socket_type_);
|
||||
|
||||
int value = 0;
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (server, ZMQ_LINGER, &value, sizeof (value)));
|
||||
|
||||
if (set_heartbeats) {
|
||||
if (set_heartbeats_) {
|
||||
value = 50;
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (server, ZMQ_HEARTBEAT_IVL, &value, sizeof (value)));
|
||||
}
|
||||
|
||||
if (is_curve)
|
||||
if (is_curve_)
|
||||
setup_curve (server, 1);
|
||||
|
||||
bind_loopback_ipv4 (server, endpoint, ep_length);
|
||||
bind_loopback_ipv4 (server, endpoint_, ep_length_);
|
||||
|
||||
// Create and connect a socket for collecting monitor events on dealer
|
||||
void *server_mon = test_context_socket (ZMQ_PAIR);
|
||||
@ -216,21 +216,21 @@ static void prep_server_socket (int set_heartbeats,
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_connect (server_mon, "inproc://monitor-dealer"));
|
||||
|
||||
*server_out = server;
|
||||
*mon_out = server_mon;
|
||||
*server_out_ = server;
|
||||
*mon_out_ = server_mon;
|
||||
}
|
||||
|
||||
// This checks for a broken TCP connection (or, in this case a stuck one
|
||||
// where the peer never responds to PINGS). There should be an accepted event
|
||||
// then a disconnect event.
|
||||
static void test_heartbeat_timeout (int server_type, int mock_ping)
|
||||
static void test_heartbeat_timeout (int server_type_, int mock_ping_)
|
||||
{
|
||||
int rc;
|
||||
char my_endpoint[MAX_SOCKET_STRING];
|
||||
|
||||
void *server, *server_mon;
|
||||
prep_server_socket (!mock_ping, 0, &server, &server_mon, my_endpoint,
|
||||
MAX_SOCKET_STRING, server_type);
|
||||
prep_server_socket (!mock_ping_, 0, &server, &server_mon, my_endpoint,
|
||||
MAX_SOCKET_STRING, server_type_);
|
||||
|
||||
struct sockaddr_in ip4addr;
|
||||
raw_socket s;
|
||||
@ -249,13 +249,13 @@ static void test_heartbeat_timeout (int server_type, int mock_ping)
|
||||
TEST_ASSERT_GREATER_THAN_INT (-1, rc);
|
||||
|
||||
// Mock a ZMTP 3 client so we can forcibly time out a connection
|
||||
mock_handshake (s, mock_ping);
|
||||
mock_handshake (s, mock_ping_);
|
||||
|
||||
// By now everything should report as connected
|
||||
rc = get_monitor_event (server_mon);
|
||||
TEST_ASSERT_EQUAL_INT (ZMQ_EVENT_ACCEPTED, rc);
|
||||
|
||||
if (!mock_ping) {
|
||||
if (!mock_ping_) {
|
||||
// We should have been disconnected
|
||||
rc = get_monitor_event (server_mon);
|
||||
TEST_ASSERT_EQUAL_INT (ZMQ_EVENT_DISCONNECTED, rc);
|
||||
@ -272,16 +272,16 @@ static void test_heartbeat_timeout (int server_type, int mock_ping)
|
||||
// to a server that is not doing any heartbeating. Then we sleep,
|
||||
// if the server disconnects the client, then we know the TTL did
|
||||
// its thing correctly.
|
||||
static void test_heartbeat_ttl (int client_type, int server_type)
|
||||
static void test_heartbeat_ttl (int client_type_, int server_type_)
|
||||
{
|
||||
int rc, value;
|
||||
char my_endpoint[MAX_SOCKET_STRING];
|
||||
|
||||
void *server, *server_mon, *client;
|
||||
prep_server_socket (0, 0, &server, &server_mon, my_endpoint,
|
||||
MAX_SOCKET_STRING, server_type);
|
||||
MAX_SOCKET_STRING, server_type_);
|
||||
|
||||
client = test_context_socket (client_type);
|
||||
client = test_context_socket (client_type_);
|
||||
|
||||
// Set the heartbeat TTL to 0.1 seconds
|
||||
value = 100;
|
||||
@ -315,17 +315,17 @@ static void test_heartbeat_ttl (int client_type, int server_type)
|
||||
// exchanged normally. There should be an accepted event on the server,
|
||||
// and then no event afterwards.
|
||||
static void
|
||||
test_heartbeat_notimeout (int is_curve, int client_type, int server_type)
|
||||
test_heartbeat_notimeout (int is_curve_, int client_type_, int server_type_)
|
||||
{
|
||||
int rc;
|
||||
char my_endpoint[MAX_SOCKET_STRING];
|
||||
|
||||
void *server, *server_mon;
|
||||
prep_server_socket (1, is_curve, &server, &server_mon, my_endpoint,
|
||||
MAX_SOCKET_STRING, server_type);
|
||||
prep_server_socket (1, is_curve_, &server, &server_mon, my_endpoint,
|
||||
MAX_SOCKET_STRING, server_type_);
|
||||
|
||||
void *client = test_context_socket (client_type);
|
||||
if (is_curve)
|
||||
void *client = test_context_socket (client_type_);
|
||||
if (is_curve_)
|
||||
setup_curve (client, 0);
|
||||
rc = zmq_connect (client, my_endpoint);
|
||||
|
||||
@ -378,18 +378,18 @@ const int deciseconds_per_millisecond = 100;
|
||||
const int heartbeat_ttl_max =
|
||||
(UINT16_MAX + 1) * deciseconds_per_millisecond - 1;
|
||||
|
||||
void test_setsockopt_heartbeat_success (const int value)
|
||||
void test_setsockopt_heartbeat_success (const int value_)
|
||||
{
|
||||
void *const socket = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (socket, ZMQ_HEARTBEAT_TTL, &value, sizeof (value)));
|
||||
zmq_setsockopt (socket, ZMQ_HEARTBEAT_TTL, &value_, sizeof (value_)));
|
||||
|
||||
int value_read;
|
||||
size_t value_read_size = sizeof (value_read);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_getsockopt (socket, ZMQ_HEARTBEAT_TTL,
|
||||
&value_read, &value_read_size));
|
||||
|
||||
TEST_ASSERT_EQUAL_INT (value - value % deciseconds_per_millisecond,
|
||||
TEST_ASSERT_EQUAL_INT (value_ - value_ % deciseconds_per_millisecond,
|
||||
value_read);
|
||||
|
||||
test_context_socket_close (socket);
|
||||
|
@ -83,33 +83,33 @@ void test_defaults ()
|
||||
TEST_ASSERT_EQUAL_INT (2000, send_count);
|
||||
}
|
||||
|
||||
int count_msg (int send_hwm, int recv_hwm, TestType testType)
|
||||
int count_msg (int send_hwm_, int recv_hwm_, TestType test_type_)
|
||||
{
|
||||
void *bind_socket;
|
||||
void *connect_socket;
|
||||
if (testType == BIND_FIRST) {
|
||||
if (test_type_ == BIND_FIRST) {
|
||||
// Set up bind socket
|
||||
bind_socket = test_context_socket (ZMQ_PULL);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (
|
||||
bind_socket, ZMQ_RCVHWM, &recv_hwm, sizeof (recv_hwm)));
|
||||
bind_socket, ZMQ_RCVHWM, &recv_hwm_, sizeof (recv_hwm_)));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bind_socket, "inproc://a"));
|
||||
|
||||
// Set up connect socket
|
||||
connect_socket = test_context_socket (ZMQ_PUSH);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (
|
||||
connect_socket, ZMQ_SNDHWM, &send_hwm, sizeof (send_hwm)));
|
||||
connect_socket, ZMQ_SNDHWM, &send_hwm_, sizeof (send_hwm_)));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connect_socket, "inproc://a"));
|
||||
} else {
|
||||
// Set up connect socket
|
||||
connect_socket = test_context_socket (ZMQ_PUSH);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (
|
||||
connect_socket, ZMQ_SNDHWM, &send_hwm, sizeof (send_hwm)));
|
||||
connect_socket, ZMQ_SNDHWM, &send_hwm_, sizeof (send_hwm_)));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connect_socket, "inproc://a"));
|
||||
|
||||
// Set up bind socket
|
||||
bind_socket = test_context_socket (ZMQ_PULL);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (
|
||||
bind_socket, ZMQ_RCVHWM, &recv_hwm, sizeof (recv_hwm)));
|
||||
bind_socket, ZMQ_RCVHWM, &recv_hwm_, sizeof (recv_hwm_)));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bind_socket, "inproc://a"));
|
||||
}
|
||||
|
||||
@ -139,22 +139,22 @@ int count_msg (int send_hwm, int recv_hwm, TestType testType)
|
||||
return send_count;
|
||||
}
|
||||
|
||||
int test_inproc_bind_first (int send_hwm, int recv_hwm)
|
||||
int test_inproc_bind_first (int send_hwm_, int recv_hwm_)
|
||||
{
|
||||
return count_msg (send_hwm, recv_hwm, BIND_FIRST);
|
||||
return count_msg (send_hwm_, recv_hwm_, BIND_FIRST);
|
||||
}
|
||||
|
||||
int test_inproc_connect_first (int send_hwm, int recv_hwm)
|
||||
int test_inproc_connect_first (int send_hwm_, int recv_hwm_)
|
||||
{
|
||||
return count_msg (send_hwm, recv_hwm, CONNECT_FIRST);
|
||||
return count_msg (send_hwm_, recv_hwm_, CONNECT_FIRST);
|
||||
}
|
||||
|
||||
int test_inproc_connect_and_close_first (int send_hwm, int recv_hwm)
|
||||
int test_inproc_connect_and_close_first (int send_hwm_, int recv_hwm_)
|
||||
{
|
||||
// Set up connect socket
|
||||
void *connect_socket = test_context_socket (ZMQ_PUSH);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (connect_socket, ZMQ_SNDHWM,
|
||||
&send_hwm, sizeof (send_hwm)));
|
||||
&send_hwm_, sizeof (send_hwm_)));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connect_socket, "inproc://a"));
|
||||
|
||||
// Send until we block
|
||||
@ -169,7 +169,7 @@ int test_inproc_connect_and_close_first (int send_hwm, int recv_hwm)
|
||||
// Set up bind socket
|
||||
void *bind_socket = test_context_socket (ZMQ_PULL);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (bind_socket, ZMQ_RCVHWM, &recv_hwm, sizeof (recv_hwm)));
|
||||
zmq_setsockopt (bind_socket, ZMQ_RCVHWM, &recv_hwm_, sizeof (recv_hwm_)));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bind_socket, "inproc://a"));
|
||||
|
||||
// Now receive all sent messages
|
||||
@ -185,7 +185,7 @@ int test_inproc_connect_and_close_first (int send_hwm, int recv_hwm)
|
||||
return send_count;
|
||||
}
|
||||
|
||||
int test_inproc_bind_and_close_first (int send_hwm, int /* recv_hwm */)
|
||||
int test_inproc_bind_and_close_first (int send_hwm_, int /* recv_hwm */)
|
||||
{
|
||||
void *ctx = zmq_ctx_new ();
|
||||
TEST_ASSERT_NOT_NULL (ctx);
|
||||
@ -194,7 +194,7 @@ int test_inproc_bind_and_close_first (int send_hwm, int /* recv_hwm */)
|
||||
void *bind_socket = zmq_socket (ctx, ZMQ_PUSH);
|
||||
TEST_ASSERT_NOT_NULL (bind_socket);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (bind_socket, ZMQ_SNDHWM, &send_hwm, sizeof (send_hwm)));
|
||||
zmq_setsockopt (bind_socket, ZMQ_SNDHWM, &send_hwm_, sizeof (send_hwm_)));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bind_socket, "inproc://a"));
|
||||
|
||||
// Send until we block
|
||||
|
@ -42,7 +42,7 @@ void tearDown ()
|
||||
|
||||
// const int MAX_SENDS = 10000;
|
||||
|
||||
int test_defaults (int send_hwm, int msgCnt)
|
||||
int test_defaults (int send_hwm_, int msg_cnt_)
|
||||
{
|
||||
// Set up bind socket
|
||||
void *pub_socket = test_context_socket (ZMQ_PUB);
|
||||
@ -54,13 +54,13 @@ int test_defaults (int send_hwm, int msgCnt)
|
||||
|
||||
//set a hwm on publisher
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (pub_socket, ZMQ_SNDHWM, &send_hwm, sizeof (send_hwm)));
|
||||
zmq_setsockopt (pub_socket, ZMQ_SNDHWM, &send_hwm_, sizeof (send_hwm_)));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (sub_socket, ZMQ_SUBSCRIBE, 0, 0));
|
||||
|
||||
// Send until we block
|
||||
int send_count = 0;
|
||||
while (send_count < msgCnt
|
||||
while (send_count < msg_cnt_
|
||||
&& zmq_send (pub_socket, NULL, 0, ZMQ_DONTWAIT) == 0)
|
||||
++send_count;
|
||||
|
||||
@ -72,7 +72,7 @@ int test_defaults (int send_hwm, int msgCnt)
|
||||
++recv_count;
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL_INT (send_hwm, recv_count);
|
||||
TEST_ASSERT_EQUAL_INT (send_hwm_, recv_count);
|
||||
|
||||
// Clean up
|
||||
test_context_socket_close (sub_socket);
|
||||
@ -81,11 +81,11 @@ int test_defaults (int send_hwm, int msgCnt)
|
||||
return recv_count;
|
||||
}
|
||||
|
||||
int receive (void *socket)
|
||||
int receive (void *socket_)
|
||||
{
|
||||
int recv_count = 0;
|
||||
// Now receive all sent messages
|
||||
while (0 == zmq_recv (socket, NULL, 0, ZMQ_DONTWAIT)) {
|
||||
while (0 == zmq_recv (socket_, NULL, 0, ZMQ_DONTWAIT)) {
|
||||
++recv_count;
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ int receive (void *socket)
|
||||
}
|
||||
|
||||
|
||||
int test_blocking (int send_hwm, int msgCnt)
|
||||
int test_blocking (int send_hwm_, int msg_cnt_)
|
||||
{
|
||||
// Set up bind socket
|
||||
void *pub_socket = test_context_socket (ZMQ_PUB);
|
||||
@ -105,7 +105,7 @@ int test_blocking (int send_hwm, int msgCnt)
|
||||
|
||||
//set a hwm on publisher
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (pub_socket, ZMQ_SNDHWM, &send_hwm, sizeof (send_hwm)));
|
||||
zmq_setsockopt (pub_socket, ZMQ_SNDHWM, &send_hwm_, sizeof (send_hwm_)));
|
||||
int wait = 1;
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (pub_socket, ZMQ_XPUB_NODROP, &wait, sizeof (wait)));
|
||||
@ -115,7 +115,7 @@ int test_blocking (int send_hwm, int msgCnt)
|
||||
// Send until we block
|
||||
int send_count = 0;
|
||||
int recv_count = 0;
|
||||
while (send_count < msgCnt) {
|
||||
while (send_count < msg_cnt_) {
|
||||
const int rc = zmq_send (pub_socket, NULL, 0, ZMQ_DONTWAIT);
|
||||
if (rc == 0) {
|
||||
++send_count;
|
||||
|
@ -44,15 +44,15 @@ static void pusher (void * /*unused*/)
|
||||
{
|
||||
// Connect first
|
||||
// do not use test_context_socket here, as it is not thread-safe
|
||||
void *connectSocket = zmq_socket (get_test_context (), ZMQ_PAIR);
|
||||
void *connect_socket = zmq_socket (get_test_context (), ZMQ_PAIR);
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connectSocket, "inproc://sink"));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connect_socket, "inproc://sink"));
|
||||
|
||||
// Queue up some data
|
||||
send_string_expect_success (connectSocket, "foobar", 0);
|
||||
send_string_expect_success (connect_socket, "foobar", 0);
|
||||
|
||||
// Cleanup
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_close (connectSocket));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_close (connect_socket));
|
||||
}
|
||||
|
||||
static void simult_conn (void *endpt_)
|
||||
@ -62,11 +62,11 @@ static void simult_conn (void *endpt_)
|
||||
|
||||
// Connect
|
||||
// do not use test_context_socket here, as it is not thread-safe
|
||||
void *connectSocket = zmq_socket (get_test_context (), ZMQ_SUB);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connectSocket, endpt));
|
||||
void *connect_socket = zmq_socket (get_test_context (), ZMQ_SUB);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connect_socket, endpt));
|
||||
|
||||
// Cleanup
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_close (connectSocket));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_close (connect_socket));
|
||||
}
|
||||
|
||||
static void simult_bind (void *endpt_)
|
||||
@ -76,96 +76,96 @@ static void simult_bind (void *endpt_)
|
||||
|
||||
// Bind
|
||||
// do not use test_context_socket here, as it is not thread-safe
|
||||
void *bindSocket = zmq_socket (get_test_context (), ZMQ_PUB);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bindSocket, endpt));
|
||||
void *bind_socket = zmq_socket (get_test_context (), ZMQ_PUB);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bind_socket, endpt));
|
||||
|
||||
// Cleanup
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_close (bindSocket));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_close (bind_socket));
|
||||
}
|
||||
|
||||
void test_bind_before_connect ()
|
||||
{
|
||||
// Bind first
|
||||
void *bindSocket = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bindSocket, "inproc://bbc"));
|
||||
void *bind_socket = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bind_socket, "inproc://bbc"));
|
||||
|
||||
// Now connect
|
||||
void *connectSocket = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connectSocket, "inproc://bbc"));
|
||||
void *connect_socket = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connect_socket, "inproc://bbc"));
|
||||
|
||||
// Queue up some data
|
||||
send_string_expect_success (connectSocket, "foobar", 0);
|
||||
send_string_expect_success (connect_socket, "foobar", 0);
|
||||
|
||||
// Read pending message
|
||||
recv_string_expect_success (bindSocket, "foobar", 0);
|
||||
recv_string_expect_success (bind_socket, "foobar", 0);
|
||||
|
||||
// Cleanup
|
||||
test_context_socket_close (connectSocket);
|
||||
test_context_socket_close (bindSocket);
|
||||
test_context_socket_close (connect_socket);
|
||||
test_context_socket_close (bind_socket);
|
||||
}
|
||||
|
||||
void test_connect_before_bind ()
|
||||
{
|
||||
// Connect first
|
||||
void *connectSocket = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connectSocket, "inproc://cbb"));
|
||||
void *connect_socket = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connect_socket, "inproc://cbb"));
|
||||
|
||||
// Queue up some data
|
||||
send_string_expect_success (connectSocket, "foobar", 0);
|
||||
send_string_expect_success (connect_socket, "foobar", 0);
|
||||
|
||||
// Now bind
|
||||
void *bindSocket = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bindSocket, "inproc://cbb"));
|
||||
void *bind_socket = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bind_socket, "inproc://cbb"));
|
||||
|
||||
// Read pending message
|
||||
recv_string_expect_success (bindSocket, "foobar", 0);
|
||||
recv_string_expect_success (bind_socket, "foobar", 0);
|
||||
|
||||
// Cleanup
|
||||
test_context_socket_close (connectSocket);
|
||||
test_context_socket_close (bindSocket);
|
||||
test_context_socket_close (connect_socket);
|
||||
test_context_socket_close (bind_socket);
|
||||
}
|
||||
|
||||
void test_connect_before_bind_pub_sub ()
|
||||
{
|
||||
// Connect first
|
||||
void *connectSocket = test_context_socket (ZMQ_PUB);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connectSocket, "inproc://cbbps"));
|
||||
void *connect_socket = test_context_socket (ZMQ_PUB);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connect_socket, "inproc://cbbps"));
|
||||
|
||||
// Queue up some data, this will be dropped
|
||||
send_string_expect_success (connectSocket, "before", 0);
|
||||
send_string_expect_success (connect_socket, "before", 0);
|
||||
|
||||
// Now bind
|
||||
void *bindSocket = test_context_socket (ZMQ_SUB);
|
||||
void *bind_socket = test_context_socket (ZMQ_SUB);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (bindSocket, ZMQ_SUBSCRIBE, "", 0));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bindSocket, "inproc://cbbps"));
|
||||
zmq_setsockopt (bind_socket, ZMQ_SUBSCRIBE, "", 0));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bind_socket, "inproc://cbbps"));
|
||||
|
||||
// Wait for pub-sub connection to happen
|
||||
msleep (SETTLE_TIME);
|
||||
|
||||
// Queue up some data, this not will be dropped
|
||||
send_string_expect_success (connectSocket, "after", 0);
|
||||
send_string_expect_success (connect_socket, "after", 0);
|
||||
|
||||
// Read pending message
|
||||
recv_string_expect_success (bindSocket, "after", 0);
|
||||
recv_string_expect_success (bind_socket, "after", 0);
|
||||
|
||||
// Cleanup
|
||||
test_context_socket_close (connectSocket);
|
||||
test_context_socket_close (bindSocket);
|
||||
test_context_socket_close (connect_socket);
|
||||
test_context_socket_close (bind_socket);
|
||||
}
|
||||
|
||||
void test_connect_before_bind_ctx_term ()
|
||||
{
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
// Connect first
|
||||
void *connectSocket = test_context_socket (ZMQ_ROUTER);
|
||||
void *connect_socket = test_context_socket (ZMQ_ROUTER);
|
||||
|
||||
char ep[20];
|
||||
sprintf (ep, "inproc://cbbrr%d", i);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connectSocket, ep));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connect_socket, ep));
|
||||
|
||||
// Cleanup
|
||||
test_context_socket_close (connectSocket);
|
||||
test_context_socket_close (connect_socket);
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,32 +173,32 @@ void test_multiple_connects ()
|
||||
{
|
||||
const unsigned int no_of_connects = 10;
|
||||
|
||||
void *connectSocket[no_of_connects];
|
||||
void *connect_socket[no_of_connects];
|
||||
|
||||
// Connect first
|
||||
for (unsigned int i = 0; i < no_of_connects; ++i) {
|
||||
connectSocket[i] = test_context_socket (ZMQ_PUSH);
|
||||
connect_socket[i] = test_context_socket (ZMQ_PUSH);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_connect (connectSocket[i], "inproc://multiple"));
|
||||
zmq_connect (connect_socket[i], "inproc://multiple"));
|
||||
|
||||
// Queue up some data
|
||||
send_string_expect_success (connectSocket[i], "foobar", 0);
|
||||
send_string_expect_success (connect_socket[i], "foobar", 0);
|
||||
}
|
||||
|
||||
// Now bind
|
||||
void *bindSocket = test_context_socket (ZMQ_PULL);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bindSocket, "inproc://multiple"));
|
||||
void *bind_socket = test_context_socket (ZMQ_PULL);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bind_socket, "inproc://multiple"));
|
||||
|
||||
for (unsigned int i = 0; i < no_of_connects; ++i) {
|
||||
recv_string_expect_success (bindSocket, "foobar", 0);
|
||||
recv_string_expect_success (bind_socket, "foobar", 0);
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
for (unsigned int i = 0; i < no_of_connects; ++i) {
|
||||
test_context_socket_close (connectSocket[i]);
|
||||
test_context_socket_close (connect_socket[i]);
|
||||
}
|
||||
|
||||
test_context_socket_close (bindSocket);
|
||||
test_context_socket_close (bind_socket);
|
||||
}
|
||||
|
||||
void test_multiple_threads ()
|
||||
@ -213,12 +213,12 @@ void test_multiple_threads ()
|
||||
}
|
||||
|
||||
// Now bind
|
||||
void *bindSocket = test_context_socket (ZMQ_PULL);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bindSocket, "inproc://sink"));
|
||||
void *bind_socket = test_context_socket (ZMQ_PULL);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bind_socket, "inproc://sink"));
|
||||
|
||||
for (unsigned int i = 0; i < no_of_threads; ++i) {
|
||||
// Read pending message
|
||||
recv_string_expect_success (bindSocket, "foobar", 0);
|
||||
recv_string_expect_success (bind_socket, "foobar", 0);
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
@ -226,7 +226,7 @@ void test_multiple_threads ()
|
||||
zmq_threadclose (threads[i]);
|
||||
}
|
||||
|
||||
test_context_socket_close (bindSocket);
|
||||
test_context_socket_close (bind_socket);
|
||||
}
|
||||
|
||||
void test_simultaneous_connect_bind_threads ()
|
||||
@ -297,50 +297,50 @@ void test_routing_id ()
|
||||
|
||||
void test_connect_only ()
|
||||
{
|
||||
void *connectSocket = test_context_socket (ZMQ_PUSH);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connectSocket, "inproc://a"));
|
||||
void *connect_socket = test_context_socket (ZMQ_PUSH);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connect_socket, "inproc://a"));
|
||||
|
||||
test_context_socket_close (connectSocket);
|
||||
test_context_socket_close (connect_socket);
|
||||
}
|
||||
|
||||
|
||||
void test_unbind ()
|
||||
{
|
||||
// Bind and unbind socket 1
|
||||
void *bindSocket1 = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bindSocket1, "inproc://unbind"));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (bindSocket1, "inproc://unbind"));
|
||||
void *bind_socket1 = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bind_socket1, "inproc://unbind"));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (bind_socket1, "inproc://unbind"));
|
||||
|
||||
// Bind socket 2
|
||||
void *bindSocket2 = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bindSocket2, "inproc://unbind"));
|
||||
void *bind_socket2 = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (bind_socket2, "inproc://unbind"));
|
||||
|
||||
// Now connect
|
||||
void *connectSocket = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connectSocket, "inproc://unbind"));
|
||||
void *connect_socket = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connect_socket, "inproc://unbind"));
|
||||
|
||||
// Queue up some data
|
||||
send_string_expect_success (connectSocket, "foobar", 0);
|
||||
send_string_expect_success (connect_socket, "foobar", 0);
|
||||
|
||||
// Read pending message
|
||||
recv_string_expect_success (bindSocket2, "foobar", 0);
|
||||
recv_string_expect_success (bind_socket2, "foobar", 0);
|
||||
|
||||
// Cleanup
|
||||
test_context_socket_close (connectSocket);
|
||||
test_context_socket_close (bindSocket1);
|
||||
test_context_socket_close (bindSocket2);
|
||||
test_context_socket_close (connect_socket);
|
||||
test_context_socket_close (bind_socket1);
|
||||
test_context_socket_close (bind_socket2);
|
||||
}
|
||||
|
||||
void test_shutdown_during_pend ()
|
||||
{
|
||||
// Connect first
|
||||
void *connectSocket = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connectSocket, "inproc://cbb"));
|
||||
void *connect_socket = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connect_socket, "inproc://cbb"));
|
||||
|
||||
zmq_ctx_shutdown (get_test_context ());
|
||||
|
||||
// Cleanup
|
||||
test_context_socket_close (connectSocket);
|
||||
test_context_socket_close (connect_socket);
|
||||
}
|
||||
|
||||
int main (void)
|
||||
|
@ -40,9 +40,9 @@ struct iovec
|
||||
};
|
||||
#endif
|
||||
|
||||
void do_check (void *sb, void *sc, size_t msg_size)
|
||||
void do_check (void *sb_, void *sc_, size_t msg_size_)
|
||||
{
|
||||
assert (sb && sc && msg_size > 0);
|
||||
assert (sb_ && sc_ && msg_size_ > 0);
|
||||
|
||||
int rc = 0;
|
||||
const char msg_val = '1';
|
||||
@ -51,39 +51,39 @@ void do_check (void *sb, void *sc, size_t msg_size)
|
||||
|
||||
send_count = recv_count = num_messages;
|
||||
|
||||
char *ref_msg = (char *) malloc (msg_size);
|
||||
char *ref_msg = (char *) malloc (msg_size_);
|
||||
assert (ref_msg);
|
||||
memset (ref_msg, msg_val, msg_size);
|
||||
memset (ref_msg, msg_val, msg_size_);
|
||||
|
||||
// zmq_sendiov(3) as a single multi-part send
|
||||
struct iovec send_iov[num_messages];
|
||||
char *buf = (char *) malloc (msg_size * num_messages);
|
||||
char *buf = (char *) malloc (msg_size_ * num_messages);
|
||||
|
||||
for (int i = 0; i < num_messages; i++) {
|
||||
send_iov[i].iov_base = &buf[i * msg_size];
|
||||
send_iov[i].iov_len = msg_size;
|
||||
memcpy (send_iov[i].iov_base, ref_msg, msg_size);
|
||||
assert (memcmp (ref_msg, send_iov[i].iov_base, msg_size) == 0);
|
||||
send_iov[i].iov_base = &buf[i * msg_size_];
|
||||
send_iov[i].iov_len = msg_size_;
|
||||
memcpy (send_iov[i].iov_base, ref_msg, msg_size_);
|
||||
assert (memcmp (ref_msg, send_iov[i].iov_base, msg_size_) == 0);
|
||||
}
|
||||
|
||||
// Test errors - zmq_recviov - null socket
|
||||
rc = zmq_sendiov (NULL, send_iov, send_count, ZMQ_SNDMORE);
|
||||
assert (rc == -1 && errno == ENOTSOCK);
|
||||
// Test errors - zmq_recviov - invalid send count
|
||||
rc = zmq_sendiov (sc, send_iov, 0, 0);
|
||||
rc = zmq_sendiov (sc_, send_iov, 0, 0);
|
||||
assert (rc == -1 && errno == EINVAL);
|
||||
// Test errors - zmq_recviov - null iovec
|
||||
rc = zmq_sendiov (sc, NULL, send_count, 0);
|
||||
rc = zmq_sendiov (sc_, NULL, send_count, 0);
|
||||
assert (rc == -1 && errno == EINVAL);
|
||||
|
||||
// Test success
|
||||
rc = zmq_sendiov (sc, send_iov, send_count, ZMQ_SNDMORE);
|
||||
rc = zmq_sendiov (sc_, send_iov, send_count, ZMQ_SNDMORE);
|
||||
// The zmq_sendiov(3) API method does not follow the same semantics as
|
||||
// zmq_recviov(3); the latter returns the count of messages sent, rightly
|
||||
// so, whilst the former sends the number of bytes successfully sent from
|
||||
// the last message, which does not hold much sense from a batch send
|
||||
// perspective; hence the assert checks if rc is same as msg_size.
|
||||
assert ((size_t) rc == msg_size);
|
||||
assert ((size_t) rc == msg_size_);
|
||||
|
||||
// zmq_recviov(3) single-shot
|
||||
struct iovec recv_iov[num_messages];
|
||||
@ -92,22 +92,22 @@ void do_check (void *sb, void *sc, size_t msg_size)
|
||||
rc = zmq_recviov (NULL, recv_iov, &recv_count, 0);
|
||||
assert (rc == -1 && errno == ENOTSOCK);
|
||||
// Test error - zmq_recviov - invalid receive count
|
||||
rc = zmq_recviov (sb, recv_iov, NULL, 0);
|
||||
rc = zmq_recviov (sb_, recv_iov, NULL, 0);
|
||||
assert (rc == -1 && errno == EINVAL);
|
||||
size_t invalid_recv_count = 0;
|
||||
rc = zmq_recviov (sb, recv_iov, &invalid_recv_count, 0);
|
||||
rc = zmq_recviov (sb_, recv_iov, &invalid_recv_count, 0);
|
||||
assert (rc == -1 && errno == EINVAL);
|
||||
// Test error - zmq_recviov - null iovec
|
||||
rc = zmq_recviov (sb, NULL, &recv_count, 0);
|
||||
rc = zmq_recviov (sb_, NULL, &recv_count, 0);
|
||||
assert (rc == -1 && errno == EINVAL);
|
||||
|
||||
// Test success
|
||||
rc = zmq_recviov (sb, recv_iov, &recv_count, 0);
|
||||
rc = zmq_recviov (sb_, recv_iov, &recv_count, 0);
|
||||
assert (rc == num_messages);
|
||||
|
||||
for (int i = 0; i < num_messages; i++) {
|
||||
assert (recv_iov[i].iov_base);
|
||||
assert (memcmp (ref_msg, recv_iov[i].iov_base, msg_size) == 0);
|
||||
assert (memcmp (ref_msg, recv_iov[i].iov_base, msg_size_) == 0);
|
||||
free (recv_iov[i].iov_base);
|
||||
}
|
||||
|
||||
|
@ -42,14 +42,14 @@ void tearDown ()
|
||||
teardown_test_context ();
|
||||
}
|
||||
|
||||
static void do_bind_and_verify (void *s, const char *endpoint)
|
||||
static void do_bind_and_verify (void *s_, const char *endpoint_)
|
||||
{
|
||||
int rc = zmq_bind (s, endpoint);
|
||||
int rc = zmq_bind (s_, endpoint_);
|
||||
assert (rc == 0);
|
||||
char reported[255];
|
||||
size_t size = 255;
|
||||
rc = zmq_getsockopt (s, ZMQ_LAST_ENDPOINT, reported, &size);
|
||||
assert (rc == 0 && strcmp (reported, endpoint) == 0);
|
||||
rc = zmq_getsockopt (s_, ZMQ_LAST_ENDPOINT, reported, &size);
|
||||
assert (rc == 0 && strcmp (reported, endpoint_) == 0);
|
||||
}
|
||||
|
||||
void test_last_endpoint ()
|
||||
|
@ -29,38 +29,38 @@
|
||||
|
||||
#include "testutil.hpp"
|
||||
|
||||
static void zap_handler (void *handler)
|
||||
static void zap_handler (void *handler_)
|
||||
{
|
||||
uint8_t metadata[] = {5, 'H', 'e', 'l', 'l', 'o', 0, 0,
|
||||
0, 5, 'W', 'o', 'r', 'l', 'd'};
|
||||
|
||||
// Process ZAP requests forever
|
||||
while (true) {
|
||||
char *version = s_recv (handler);
|
||||
char *version = s_recv (handler_);
|
||||
if (!version)
|
||||
break; // Terminating
|
||||
|
||||
char *sequence = s_recv (handler);
|
||||
char *domain = s_recv (handler);
|
||||
char *address = s_recv (handler);
|
||||
char *routing_id = s_recv (handler);
|
||||
char *mechanism = s_recv (handler);
|
||||
char *sequence = s_recv (handler_);
|
||||
char *domain = s_recv (handler_);
|
||||
char *address = s_recv (handler_);
|
||||
char *routing_id = s_recv (handler_);
|
||||
char *mechanism = s_recv (handler_);
|
||||
|
||||
assert (streq (version, "1.0"));
|
||||
assert (streq (mechanism, "NULL"));
|
||||
|
||||
s_sendmore (handler, version);
|
||||
s_sendmore (handler, sequence);
|
||||
s_sendmore (handler_, version);
|
||||
s_sendmore (handler_, sequence);
|
||||
if (streq (domain, "DOMAIN")) {
|
||||
s_sendmore (handler, "200");
|
||||
s_sendmore (handler, "OK");
|
||||
s_sendmore (handler, "anonymous");
|
||||
zmq_send (handler, metadata, sizeof (metadata), 0);
|
||||
s_sendmore (handler_, "200");
|
||||
s_sendmore (handler_, "OK");
|
||||
s_sendmore (handler_, "anonymous");
|
||||
zmq_send (handler_, metadata, sizeof (metadata), 0);
|
||||
} else {
|
||||
s_sendmore (handler, "400");
|
||||
s_sendmore (handler, "BAD DOMAIN");
|
||||
s_sendmore (handler, "");
|
||||
s_send (handler, "");
|
||||
s_sendmore (handler_, "400");
|
||||
s_sendmore (handler_, "BAD DOMAIN");
|
||||
s_sendmore (handler_, "");
|
||||
s_send (handler_, "");
|
||||
}
|
||||
free (version);
|
||||
free (sequence);
|
||||
@ -69,7 +69,7 @@ static void zap_handler (void *handler)
|
||||
free (routing_id);
|
||||
free (mechanism);
|
||||
}
|
||||
close_zero_linger (handler);
|
||||
close_zero_linger (handler_);
|
||||
}
|
||||
|
||||
int main (void)
|
||||
|
@ -29,11 +29,11 @@
|
||||
|
||||
#include "testutil.hpp"
|
||||
|
||||
void ffn (void *data, void *hint)
|
||||
void ffn (void *data_, void *hint_)
|
||||
{
|
||||
// Signal that ffn has been called by writing "freed" to hint
|
||||
(void) data; // Suppress 'unused' warnings at compile time
|
||||
memcpy (hint, (void *) "freed", 5);
|
||||
(void) data_; // Suppress 'unused' warnings at compile time
|
||||
memcpy (hint_, (void *) "freed", 5);
|
||||
}
|
||||
|
||||
int main (void)
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
#include "testutil.hpp"
|
||||
|
||||
typedef void (*extra_func_t) (void *socket);
|
||||
typedef void (*extra_func_t) (void *socket_);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT
|
||||
void set_sockopt_fastpath (void *socket)
|
||||
@ -41,7 +41,7 @@ void set_sockopt_fastpath (void *socket)
|
||||
}
|
||||
#endif
|
||||
|
||||
void test_pair_tcp (extra_func_t extra_func = NULL)
|
||||
void test_pair_tcp (extra_func_t extra_func_ = NULL)
|
||||
{
|
||||
size_t len = MAX_SOCKET_STRING;
|
||||
char my_endpoint[MAX_SOCKET_STRING];
|
||||
@ -51,8 +51,8 @@ void test_pair_tcp (extra_func_t extra_func = NULL)
|
||||
void *sb = zmq_socket (ctx, ZMQ_PAIR);
|
||||
assert (sb);
|
||||
|
||||
if (extra_func)
|
||||
extra_func (sb);
|
||||
if (extra_func_)
|
||||
extra_func_ (sb);
|
||||
|
||||
int rc = zmq_bind (sb, "tcp://127.0.0.1:*");
|
||||
assert (rc == 0);
|
||||
@ -61,8 +61,8 @@ void test_pair_tcp (extra_func_t extra_func = NULL)
|
||||
|
||||
void *sc = zmq_socket (ctx, ZMQ_PAIR);
|
||||
assert (sc);
|
||||
if (extra_func)
|
||||
extra_func (sc);
|
||||
if (extra_func_)
|
||||
extra_func_ (sc);
|
||||
|
||||
rc = zmq_connect (sc, my_endpoint);
|
||||
assert (rc == 0);
|
||||
|
@ -43,11 +43,11 @@ void tearDown ()
|
||||
teardown_test_context ();
|
||||
}
|
||||
|
||||
fd_t get_fd (void *socket)
|
||||
fd_t get_fd (void *socket_)
|
||||
{
|
||||
fd_t fd;
|
||||
size_t fd_size = sizeof fd;
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_getsockopt (socket, ZMQ_FD, &fd, &fd_size));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_getsockopt (socket_, ZMQ_FD, &fd, &fd_size));
|
||||
return fd;
|
||||
}
|
||||
|
||||
@ -224,25 +224,25 @@ void test_null_socket_pointers ()
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_destroy (&poller));
|
||||
}
|
||||
|
||||
typedef void (*extra_poller_socket_func_t) (void *poller, void *socket);
|
||||
typedef void (*extra_poller_socket_func_t) (void *poller_, void *socket_);
|
||||
|
||||
void test_with_empty_poller (extra_poller_socket_func_t extra_func)
|
||||
void test_with_empty_poller (extra_poller_socket_func_t extra_func_)
|
||||
{
|
||||
void *socket = test_context_socket (ZMQ_PAIR);
|
||||
|
||||
void *poller = zmq_poller_new ();
|
||||
TEST_ASSERT_NOT_NULL (poller);
|
||||
|
||||
extra_func (poller, socket);
|
||||
extra_func_ (poller, socket);
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_destroy (&poller));
|
||||
|
||||
test_context_socket_close (socket);
|
||||
}
|
||||
|
||||
typedef void (*extra_poller_func_t) (void *poller);
|
||||
typedef void (*extra_poller_func_t) (void *poller_);
|
||||
|
||||
void test_with_valid_poller (extra_poller_func_t extra_func)
|
||||
void test_with_valid_poller (extra_poller_func_t extra_func_)
|
||||
{
|
||||
void *socket = test_context_socket (ZMQ_PAIR);
|
||||
|
||||
@ -252,25 +252,25 @@ void test_with_valid_poller (extra_poller_func_t extra_func)
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_poller_add (poller, socket, NULL, ZMQ_POLLIN));
|
||||
|
||||
extra_func (poller);
|
||||
extra_func_ (poller);
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_destroy (&poller));
|
||||
|
||||
test_context_socket_close (socket);
|
||||
}
|
||||
|
||||
void call_poller_wait_null_event_fails (void *poller)
|
||||
void call_poller_wait_null_event_fails (void *poller_)
|
||||
{
|
||||
TEST_ASSERT_FAILURE_ERRNO (EFAULT, zmq_poller_wait (poller, NULL, 0));
|
||||
TEST_ASSERT_FAILURE_ERRNO (EFAULT, zmq_poller_wait (poller_, NULL, 0));
|
||||
}
|
||||
|
||||
void call_poller_wait_all_null_event_fails_event_count_nonzero (void *poller)
|
||||
void call_poller_wait_all_null_event_fails_event_count_nonzero (void *poller_)
|
||||
{
|
||||
TEST_ASSERT_FAILURE_ERRNO (EFAULT,
|
||||
zmq_poller_wait_all (poller, NULL, 1, 0));
|
||||
zmq_poller_wait_all (poller_, NULL, 1, 0));
|
||||
}
|
||||
|
||||
void call_poller_wait_all_null_event_fails_event_count_zero (void *poller)
|
||||
void call_poller_wait_all_null_event_fails_event_count_zero (void *poller_)
|
||||
{
|
||||
#if 0
|
||||
// TODO this causes an assertion, which is not consistent if the number
|
||||
@ -289,119 +289,121 @@ TEST_CASE_FUNC_PARAM (call_poller_wait_all_null_event_fails_event_count_nonzero,
|
||||
TEST_CASE_FUNC_PARAM (call_poller_wait_all_null_event_fails_event_count_zero,
|
||||
test_with_valid_poller)
|
||||
|
||||
void call_poller_add_twice_fails (void *poller, void *socket)
|
||||
void call_poller_add_twice_fails (void *poller_, void *socket_)
|
||||
{
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_poller_add (poller, socket, NULL, ZMQ_POLLIN));
|
||||
zmq_poller_add (poller_, socket_, NULL, ZMQ_POLLIN));
|
||||
|
||||
// attempt to add the same socket twice
|
||||
TEST_ASSERT_FAILURE_ERRNO (
|
||||
EINVAL, zmq_poller_add (poller, socket, NULL, ZMQ_POLLIN));
|
||||
EINVAL, zmq_poller_add (poller_, socket_, NULL, ZMQ_POLLIN));
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_remove (poller, socket));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_remove (poller_, socket_));
|
||||
}
|
||||
|
||||
void call_poller_remove_unregistered_fails (void *poller, void *socket)
|
||||
void call_poller_remove_unregistered_fails (void *poller_, void *socket_)
|
||||
{
|
||||
// attempt to remove socket that is not present
|
||||
TEST_ASSERT_FAILURE_ERRNO (EINVAL, zmq_poller_remove (poller, socket));
|
||||
TEST_ASSERT_FAILURE_ERRNO (EINVAL, zmq_poller_remove (poller_, socket_));
|
||||
}
|
||||
|
||||
void call_poller_modify_unregistered_fails (void *poller, void *socket)
|
||||
void call_poller_modify_unregistered_fails (void *poller_, void *socket_)
|
||||
{
|
||||
// attempt to modify socket that is not present
|
||||
TEST_ASSERT_FAILURE_ERRNO (EINVAL,
|
||||
zmq_poller_modify (poller, socket, ZMQ_POLLIN));
|
||||
TEST_ASSERT_FAILURE_ERRNO (
|
||||
EINVAL, zmq_poller_modify (poller_, socket_, ZMQ_POLLIN));
|
||||
}
|
||||
|
||||
void call_poller_add_no_events (void *poller, void *socket)
|
||||
void call_poller_add_no_events (void *poller_, void *socket_)
|
||||
{
|
||||
// add a socket with no events initially (may be activated later with
|
||||
// zmq_poller_modify)
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_add (poller, socket, NULL, 0));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_add (poller_, socket_, NULL, 0));
|
||||
// TODO test that no events are signalled
|
||||
}
|
||||
|
||||
void call_poller_modify_no_events (void *poller, void *socket)
|
||||
void call_poller_modify_no_events (void *poller_, void *socket_)
|
||||
{
|
||||
// deactivates all events for a socket temporarily (may be activated again
|
||||
// later with zmq_poller_modify)
|
||||
zmq_poller_add (poller, socket, NULL, ZMQ_POLLIN);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_modify (poller, socket, 0));
|
||||
zmq_poller_add (poller_, socket_, NULL, ZMQ_POLLIN);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_modify (poller_, socket_, 0));
|
||||
// TODO test that no events are signalled
|
||||
}
|
||||
|
||||
void call_poller_add_fd_twice_fails (void *poller, void * /*zeromq_socket*/)
|
||||
void call_poller_add_fd_twice_fails (void *poller_, void * /*zeromq_socket*/)
|
||||
{
|
||||
fd_t plain_socket = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_poller_add_fd (poller, plain_socket, NULL, ZMQ_POLLIN));
|
||||
zmq_poller_add_fd (poller_, plain_socket, NULL, ZMQ_POLLIN));
|
||||
|
||||
// attempt to add the same plain socket twice
|
||||
TEST_ASSERT_FAILURE_ERRNO (
|
||||
EINVAL, zmq_poller_add_fd (poller, plain_socket, NULL, ZMQ_POLLIN));
|
||||
EINVAL, zmq_poller_add_fd (poller_, plain_socket, NULL, ZMQ_POLLIN));
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_remove_fd (poller, plain_socket));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_remove_fd (poller_, plain_socket));
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (close (plain_socket));
|
||||
}
|
||||
|
||||
void call_poller_remove_fd_unregistered_fails (void *poller,
|
||||
void call_poller_remove_fd_unregistered_fails (void *poller_,
|
||||
void * /*zeromq_socket*/)
|
||||
{
|
||||
fd_t plain_socket = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
// attempt to remove plain socket that is not present
|
||||
TEST_ASSERT_FAILURE_ERRNO (EINVAL,
|
||||
zmq_poller_remove_fd (poller, plain_socket));
|
||||
zmq_poller_remove_fd (poller_, plain_socket));
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (close (plain_socket));
|
||||
}
|
||||
|
||||
void call_poller_modify_fd_unregistered_fails (void *poller,
|
||||
void call_poller_modify_fd_unregistered_fails (void *poller_,
|
||||
void * /*zeromq_socket*/)
|
||||
{
|
||||
fd_t plain_socket = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
// attempt to remove plain socket that is not present
|
||||
TEST_ASSERT_FAILURE_ERRNO (
|
||||
EINVAL, zmq_poller_modify_fd (poller, plain_socket, ZMQ_POLLIN));
|
||||
EINVAL, zmq_poller_modify_fd (poller_, plain_socket, ZMQ_POLLIN));
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (close (plain_socket));
|
||||
}
|
||||
|
||||
void call_poller_add_invalid_events_fails (void *poller, void *zeromq_socket)
|
||||
void call_poller_add_invalid_events_fails (void *poller_, void *zeromq_socket_)
|
||||
{
|
||||
TEST_ASSERT_FAILURE_ERRNO (
|
||||
EINVAL, zmq_poller_add (poller, zeromq_socket, NULL, SHRT_MAX));
|
||||
EINVAL, zmq_poller_add (poller_, zeromq_socket_, NULL, SHRT_MAX));
|
||||
}
|
||||
|
||||
void call_poller_modify_invalid_events_fails (void *poller, void *zeromq_socket)
|
||||
void call_poller_modify_invalid_events_fails (void *poller_,
|
||||
void *zeromq_socket_)
|
||||
{
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_add (poller, zeromq_socket, NULL, 0));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_poller_add (poller_, zeromq_socket_, NULL, 0));
|
||||
|
||||
TEST_ASSERT_FAILURE_ERRNO (
|
||||
EINVAL, zmq_poller_modify (poller, zeromq_socket, SHRT_MAX));
|
||||
EINVAL, zmq_poller_modify (poller_, zeromq_socket_, SHRT_MAX));
|
||||
}
|
||||
|
||||
void call_poller_add_fd_invalid_events_fails (void *poller,
|
||||
void call_poller_add_fd_invalid_events_fails (void *poller_,
|
||||
void * /*zeromq_socket*/)
|
||||
{
|
||||
fd_t plain_socket = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
TEST_ASSERT_FAILURE_ERRNO (
|
||||
EINVAL, zmq_poller_add_fd (poller, plain_socket, NULL, SHRT_MAX));
|
||||
EINVAL, zmq_poller_add_fd (poller_, plain_socket, NULL, SHRT_MAX));
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (close (plain_socket));
|
||||
}
|
||||
|
||||
void call_poller_modify_fd_invalid_events_fails (void *poller,
|
||||
void call_poller_modify_fd_invalid_events_fails (void *poller_,
|
||||
void * /*zeromq_socket*/)
|
||||
{
|
||||
fd_t plain_socket = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_poller_add_fd (poller, plain_socket, NULL, 0));
|
||||
zmq_poller_add_fd (poller_, plain_socket, NULL, 0));
|
||||
TEST_ASSERT_FAILURE_ERRNO (
|
||||
EINVAL, zmq_poller_modify_fd (poller, plain_socket, SHRT_MAX));
|
||||
EINVAL, zmq_poller_modify_fd (poller_, plain_socket, SHRT_MAX));
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (close (plain_socket));
|
||||
}
|
||||
@ -428,44 +430,45 @@ TEST_CASE_FUNC_PARAM (call_poller_add_fd_invalid_events_fails,
|
||||
TEST_CASE_FUNC_PARAM (call_poller_modify_fd_invalid_events_fails,
|
||||
test_with_empty_poller)
|
||||
|
||||
void call_poller_wait_empty_with_timeout_fails (void *poller, void * /*socket*/)
|
||||
void call_poller_wait_empty_with_timeout_fails (void *poller_,
|
||||
void * /*socket*/)
|
||||
{
|
||||
zmq_poller_event_t event;
|
||||
// waiting on poller with no registered sockets should report error
|
||||
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_poller_wait (poller, &event, 0));
|
||||
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_poller_wait (poller_, &event, 0));
|
||||
}
|
||||
|
||||
void call_poller_wait_empty_without_timeout_fails (void *poller,
|
||||
void call_poller_wait_empty_without_timeout_fails (void *poller_,
|
||||
void * /*socket*/)
|
||||
{
|
||||
zmq_poller_event_t event;
|
||||
// this would never be able to return since no socket was registered, and should yield an error
|
||||
TEST_ASSERT_FAILURE_ERRNO (EFAULT, zmq_poller_wait (poller, &event, -1));
|
||||
TEST_ASSERT_FAILURE_ERRNO (EFAULT, zmq_poller_wait (poller_, &event, -1));
|
||||
}
|
||||
|
||||
void call_poller_wait_all_empty_negative_count_fails (void *poller,
|
||||
void call_poller_wait_all_empty_negative_count_fails (void *poller_,
|
||||
void * /*socket*/)
|
||||
{
|
||||
zmq_poller_event_t event;
|
||||
TEST_ASSERT_FAILURE_ERRNO (EINVAL,
|
||||
zmq_poller_wait_all (poller, &event, -1, 0));
|
||||
zmq_poller_wait_all (poller_, &event, -1, 0));
|
||||
}
|
||||
|
||||
void call_poller_wait_all_empty_without_timeout_fails (void *poller,
|
||||
void call_poller_wait_all_empty_without_timeout_fails (void *poller_,
|
||||
void * /*socket*/)
|
||||
{
|
||||
zmq_poller_event_t event;
|
||||
TEST_ASSERT_FAILURE_ERRNO (EAGAIN,
|
||||
zmq_poller_wait_all (poller, &event, 0, 0));
|
||||
zmq_poller_wait_all (poller_, &event, 0, 0));
|
||||
}
|
||||
|
||||
void call_poller_wait_all_empty_with_timeout_fails (void *poller,
|
||||
void call_poller_wait_all_empty_with_timeout_fails (void *poller_,
|
||||
void * /*socket*/)
|
||||
{
|
||||
zmq_poller_event_t event;
|
||||
// this would never be able to return since no socket was registered, and should yield an error
|
||||
TEST_ASSERT_FAILURE_ERRNO (EFAULT,
|
||||
zmq_poller_wait_all (poller, &event, 0, -1));
|
||||
zmq_poller_wait_all (poller_, &event, 0, -1));
|
||||
}
|
||||
|
||||
TEST_CASE_FUNC_PARAM (call_poller_wait_empty_with_timeout_fails,
|
||||
|
@ -74,9 +74,9 @@ void *g_clients_pkts_out = NULL;
|
||||
void *g_workers_pkts_out = NULL;
|
||||
|
||||
|
||||
static void client_task (void *db)
|
||||
static void client_task (void *db_)
|
||||
{
|
||||
struct thread_data *databag = (struct thread_data *) db;
|
||||
struct thread_data *databag = (struct thread_data *) db_;
|
||||
// Endpoint socket gets random port to avoid test failing when port in use
|
||||
void *endpoint = zmq_socket (databag->ctx, ZMQ_PAIR);
|
||||
assert (endpoint);
|
||||
@ -190,14 +190,14 @@ static void client_task (void *db)
|
||||
// one request at a time but one client can talk to multiple workers at
|
||||
// once.
|
||||
|
||||
static void server_worker (void *ctx);
|
||||
static void server_worker (void *ctx_);
|
||||
|
||||
void server_task (void *ctx)
|
||||
void server_task (void *ctx_)
|
||||
{
|
||||
// Frontend socket talks to clients over TCP
|
||||
size_t len = MAX_SOCKET_STRING;
|
||||
char my_endpoint[MAX_SOCKET_STRING];
|
||||
void *frontend = zmq_socket (ctx, ZMQ_ROUTER);
|
||||
void *frontend = zmq_socket (ctx_, ZMQ_ROUTER);
|
||||
assert (frontend);
|
||||
int linger = 0;
|
||||
int rc = zmq_setsockopt (frontend, ZMQ_LINGER, &linger, sizeof (linger));
|
||||
@ -208,7 +208,7 @@ void server_task (void *ctx)
|
||||
assert (rc == 0);
|
||||
|
||||
// Backend socket talks to workers over inproc
|
||||
void *backend = zmq_socket (ctx, ZMQ_DEALER);
|
||||
void *backend = zmq_socket (ctx_, ZMQ_DEALER);
|
||||
assert (backend);
|
||||
rc = zmq_setsockopt (backend, ZMQ_LINGER, &linger, sizeof (linger));
|
||||
assert (rc == 0);
|
||||
@ -216,7 +216,7 @@ void server_task (void *ctx)
|
||||
assert (rc == 0);
|
||||
|
||||
// Control socket receives terminate command from main over inproc
|
||||
void *control = zmq_socket (ctx, ZMQ_REP);
|
||||
void *control = zmq_socket (ctx_, ZMQ_REP);
|
||||
assert (control);
|
||||
rc = zmq_setsockopt (control, ZMQ_LINGER, &linger, sizeof (linger));
|
||||
assert (rc == 0);
|
||||
@ -227,13 +227,13 @@ void server_task (void *ctx)
|
||||
int thread_nbr;
|
||||
void *threads[5];
|
||||
for (thread_nbr = 0; thread_nbr < QT_WORKERS; thread_nbr++)
|
||||
threads[thread_nbr] = zmq_threadstart (&server_worker, ctx);
|
||||
threads[thread_nbr] = zmq_threadstart (&server_worker, ctx_);
|
||||
|
||||
// Endpoint socket sends random port to avoid test failing when port in use
|
||||
void *endpoint_receivers[QT_CLIENTS];
|
||||
char endpoint_source[256];
|
||||
for (int i = 0; i < QT_CLIENTS; ++i) {
|
||||
endpoint_receivers[i] = zmq_socket (ctx, ZMQ_PAIR);
|
||||
endpoint_receivers[i] = zmq_socket (ctx_, ZMQ_PAIR);
|
||||
assert (endpoint_receivers[i]);
|
||||
rc = zmq_setsockopt (endpoint_receivers[i], ZMQ_LINGER, &linger,
|
||||
sizeof (linger));
|
||||
@ -271,9 +271,9 @@ void server_task (void *ctx)
|
||||
// of replies back, with random delays between replies:
|
||||
// The comments in the first column, if suppressed, makes it a poller version
|
||||
|
||||
static void server_worker (void *ctx)
|
||||
static void server_worker (void *ctx_)
|
||||
{
|
||||
void *worker = zmq_socket (ctx, ZMQ_DEALER);
|
||||
void *worker = zmq_socket (ctx_, ZMQ_DEALER);
|
||||
assert (worker);
|
||||
int linger = 0;
|
||||
int rc = zmq_setsockopt (worker, ZMQ_LINGER, &linger, sizeof (linger));
|
||||
@ -282,7 +282,7 @@ static void server_worker (void *ctx)
|
||||
assert (rc == 0);
|
||||
|
||||
// Control socket receives terminate command from main over inproc
|
||||
void *control = zmq_socket (ctx, ZMQ_SUB);
|
||||
void *control = zmq_socket (ctx_, ZMQ_SUB);
|
||||
assert (control);
|
||||
rc = zmq_setsockopt (control, ZMQ_SUBSCRIBE, "", 0);
|
||||
assert (rc == 0);
|
||||
@ -346,14 +346,14 @@ static void server_worker (void *ctx)
|
||||
assert (rc == 0);
|
||||
}
|
||||
|
||||
uint64_t recv_stat (void *sock, bool last)
|
||||
uint64_t recv_stat (void *sock_, bool last_)
|
||||
{
|
||||
uint64_t res;
|
||||
zmq_msg_t stats_msg;
|
||||
|
||||
int rc = zmq_msg_init (&stats_msg);
|
||||
assert (rc == 0);
|
||||
rc = zmq_recvmsg (sock, &stats_msg, 0);
|
||||
rc = zmq_recvmsg (sock_, &stats_msg, 0);
|
||||
assert (rc == sizeof (uint64_t));
|
||||
memcpy (&res, zmq_msg_data (&stats_msg), zmq_msg_size (&stats_msg));
|
||||
rc = zmq_msg_close (&stats_msg);
|
||||
@ -361,34 +361,34 @@ uint64_t recv_stat (void *sock, bool last)
|
||||
|
||||
int more;
|
||||
size_t moresz = sizeof more;
|
||||
rc = zmq_getsockopt (sock, ZMQ_RCVMORE, &more, &moresz);
|
||||
rc = zmq_getsockopt (sock_, ZMQ_RCVMORE, &more, &moresz);
|
||||
assert (rc == 0);
|
||||
assert ((last && !more) || (!last && more));
|
||||
assert ((last_ && !more) || (!last_ && more));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// Utility function to interrogate the proxy:
|
||||
|
||||
void check_proxy_stats (void *control_proxy)
|
||||
void check_proxy_stats (void *control_proxy_)
|
||||
{
|
||||
zmq_proxy_stats_t total_stats;
|
||||
int rc;
|
||||
|
||||
rc = zmq_send (control_proxy, "STATISTICS", 10, 0);
|
||||
rc = zmq_send (control_proxy_, "STATISTICS", 10, 0);
|
||||
assert (rc == 10);
|
||||
|
||||
// first frame of the reply contains FRONTEND stats:
|
||||
total_stats.frontend.msg_in = recv_stat (control_proxy, false);
|
||||
total_stats.frontend.bytes_in = recv_stat (control_proxy, false);
|
||||
total_stats.frontend.msg_out = recv_stat (control_proxy, false);
|
||||
total_stats.frontend.bytes_out = recv_stat (control_proxy, false);
|
||||
total_stats.frontend.msg_in = recv_stat (control_proxy_, false);
|
||||
total_stats.frontend.bytes_in = recv_stat (control_proxy_, false);
|
||||
total_stats.frontend.msg_out = recv_stat (control_proxy_, false);
|
||||
total_stats.frontend.bytes_out = recv_stat (control_proxy_, false);
|
||||
|
||||
// second frame of the reply contains BACKEND stats:
|
||||
total_stats.backend.msg_in = recv_stat (control_proxy, false);
|
||||
total_stats.backend.bytes_in = recv_stat (control_proxy, false);
|
||||
total_stats.backend.msg_out = recv_stat (control_proxy, false);
|
||||
total_stats.backend.bytes_out = recv_stat (control_proxy, true);
|
||||
total_stats.backend.msg_in = recv_stat (control_proxy_, false);
|
||||
total_stats.backend.bytes_in = recv_stat (control_proxy_, false);
|
||||
total_stats.backend.msg_out = recv_stat (control_proxy_, false);
|
||||
total_stats.backend.bytes_out = recv_stat (control_proxy_, true);
|
||||
|
||||
// check stats
|
||||
|
||||
|
@ -33,11 +33,11 @@
|
||||
// This is our server task.
|
||||
// It runs a proxy with a single REP socket as both frontend and backend.
|
||||
|
||||
void server_task (void *ctx)
|
||||
void server_task (void *ctx_)
|
||||
{
|
||||
size_t len = MAX_SOCKET_STRING;
|
||||
char my_endpoint[MAX_SOCKET_STRING];
|
||||
void *rep = zmq_socket (ctx, ZMQ_REP);
|
||||
void *rep = zmq_socket (ctx_, ZMQ_REP);
|
||||
assert (rep);
|
||||
int rc = zmq_bind (rep, "tcp://127.0.0.1:*");
|
||||
assert (rc == 0);
|
||||
@ -45,7 +45,7 @@ void server_task (void *ctx)
|
||||
assert (rc == 0);
|
||||
|
||||
// Control socket receives terminate command from main over inproc
|
||||
void *control = zmq_socket (ctx, ZMQ_REQ);
|
||||
void *control = zmq_socket (ctx_, ZMQ_REQ);
|
||||
assert (control);
|
||||
rc = zmq_connect (control, "inproc://control");
|
||||
assert (rc == 0);
|
||||
|
@ -34,12 +34,12 @@
|
||||
// but there is no pull on the other side, previously the proxy blocks
|
||||
// in writing to the backend, preventing the proxy from terminating
|
||||
|
||||
void server_task (void *ctx)
|
||||
void server_task (void *ctx_)
|
||||
{
|
||||
size_t len = MAX_SOCKET_STRING;
|
||||
char my_endpoint[MAX_SOCKET_STRING];
|
||||
// Frontend socket talks to main process
|
||||
void *frontend = zmq_socket (ctx, ZMQ_SUB);
|
||||
void *frontend = zmq_socket (ctx_, ZMQ_SUB);
|
||||
assert (frontend);
|
||||
int rc = zmq_setsockopt (frontend, ZMQ_SUBSCRIBE, "", 0);
|
||||
assert (rc == 0);
|
||||
@ -49,13 +49,13 @@ void server_task (void *ctx)
|
||||
assert (rc == 0);
|
||||
|
||||
// Nice socket which is never read
|
||||
void *backend = zmq_socket (ctx, ZMQ_PUSH);
|
||||
void *backend = zmq_socket (ctx_, ZMQ_PUSH);
|
||||
assert (backend);
|
||||
rc = zmq_bind (backend, "tcp://127.0.0.1:*");
|
||||
assert (rc == 0);
|
||||
|
||||
// Control socket receives terminate command from main over inproc
|
||||
void *control = zmq_socket (ctx, ZMQ_REQ);
|
||||
void *control = zmq_socket (ctx_, ZMQ_REQ);
|
||||
assert (control);
|
||||
rc = zmq_connect (control, "inproc://control");
|
||||
assert (rc == 0);
|
||||
|
@ -55,29 +55,29 @@ void test ()
|
||||
|
||||
// Subscribe pub1 to one prefix
|
||||
// and pub2 to another prefix.
|
||||
const char PREFIX1[] = "prefix1";
|
||||
const char PREFIX2[] = "p2";
|
||||
const char prefi_x1[] = "prefix1";
|
||||
const char prefi_x2[] = "p2";
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (sub1, ZMQ_SUBSCRIBE, PREFIX1, strlen (PREFIX1)));
|
||||
zmq_setsockopt (sub1, ZMQ_SUBSCRIBE, prefi_x1, strlen (prefi_x1)));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (sub2, ZMQ_SUBSCRIBE, PREFIX2, strlen (PREFIX2)));
|
||||
zmq_setsockopt (sub2, ZMQ_SUBSCRIBE, prefi_x2, strlen (prefi_x2)));
|
||||
|
||||
// Send a message with the first prefix
|
||||
send_string_expect_success (pub, PREFIX1, 0);
|
||||
send_string_expect_success (pub, prefi_x1, 0);
|
||||
msleep (SETTLE_TIME);
|
||||
|
||||
// sub1 should receive it, but not sub2
|
||||
recv_string_expect_success (sub1, PREFIX1, ZMQ_DONTWAIT);
|
||||
recv_string_expect_success (sub1, prefi_x1, ZMQ_DONTWAIT);
|
||||
|
||||
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_recv (sub2, NULL, 0, ZMQ_DONTWAIT));
|
||||
|
||||
// Send a message with the second prefix
|
||||
send_string_expect_success (pub, PREFIX2, 0);
|
||||
send_string_expect_success (pub, prefi_x2, 0);
|
||||
msleep (SETTLE_TIME);
|
||||
|
||||
// sub2 should receive it, but not sub1
|
||||
recv_string_expect_success (sub2, PREFIX2, ZMQ_DONTWAIT);
|
||||
recv_string_expect_success (sub2, prefi_x2, ZMQ_DONTWAIT);
|
||||
|
||||
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_recv (sub1, NULL, 0, ZMQ_DONTWAIT));
|
||||
|
||||
@ -93,20 +93,20 @@ void test ()
|
||||
zmq_setsockopt (sub2, ZMQ_INVERT_MATCHING, &invert, sizeof (invert)));
|
||||
|
||||
// Send a message with the first prefix
|
||||
send_string_expect_success (pub, PREFIX1, 0);
|
||||
send_string_expect_success (pub, prefi_x1, 0);
|
||||
msleep (SETTLE_TIME);
|
||||
|
||||
// sub2 should receive it, but not sub1
|
||||
recv_string_expect_success (sub2, PREFIX1, ZMQ_DONTWAIT);
|
||||
recv_string_expect_success (sub2, prefi_x1, ZMQ_DONTWAIT);
|
||||
|
||||
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_recv (sub1, NULL, 0, ZMQ_DONTWAIT));
|
||||
|
||||
// Send a message with the second prefix
|
||||
send_string_expect_success (pub, PREFIX2, 0);
|
||||
send_string_expect_success (pub, prefi_x2, 0);
|
||||
msleep (SETTLE_TIME);
|
||||
|
||||
// sub1 should receive it, but not sub2
|
||||
recv_string_expect_success (sub1, PREFIX2, ZMQ_DONTWAIT);
|
||||
recv_string_expect_success (sub1, prefi_x2, ZMQ_DONTWAIT);
|
||||
|
||||
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_recv (sub2, NULL, 0, ZMQ_DONTWAIT));
|
||||
|
||||
|
@ -42,27 +42,28 @@ void tearDown ()
|
||||
teardown_test_context ();
|
||||
}
|
||||
|
||||
void test_reconnect_ivl_against_pair_socket (const char *my_endpoint, void *sb)
|
||||
void test_reconnect_ivl_against_pair_socket (const char *my_endpoint_,
|
||||
void *sb_)
|
||||
{
|
||||
void *sc = test_context_socket (ZMQ_PAIR);
|
||||
int interval = -1;
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (sc, ZMQ_RECONNECT_IVL, &interval, sizeof (int)));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint_));
|
||||
|
||||
bounce (sb, sc);
|
||||
bounce (sb_, sc);
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb, my_endpoint));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb_, my_endpoint_));
|
||||
|
||||
expect_bounce_fail (sb, sc);
|
||||
expect_bounce_fail (sb_, sc);
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, my_endpoint));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb_, my_endpoint_));
|
||||
|
||||
expect_bounce_fail (sb, sc);
|
||||
expect_bounce_fail (sb_, sc);
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint_));
|
||||
|
||||
bounce (sb, sc);
|
||||
bounce (sb_, sc);
|
||||
|
||||
test_context_socket_close (sc);
|
||||
}
|
||||
@ -79,13 +80,13 @@ void test_reconnect_ivl_ipc (void)
|
||||
}
|
||||
#endif
|
||||
|
||||
void test_reconnect_ivl_tcp (const char *address)
|
||||
void test_reconnect_ivl_tcp (const char *address_)
|
||||
{
|
||||
size_t len = MAX_SOCKET_STRING;
|
||||
char my_endpoint[MAX_SOCKET_STRING];
|
||||
|
||||
void *sb = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, address));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, address_));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, my_endpoint, &len));
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
#include "testutil.hpp"
|
||||
|
||||
static void bounce (void *socket)
|
||||
static void bounce (void *socket_)
|
||||
{
|
||||
int more;
|
||||
size_t more_size = sizeof (more);
|
||||
@ -38,28 +38,28 @@ static void bounce (void *socket)
|
||||
int rc = zmq_msg_init (&recv_part);
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_msg_recv (&recv_part, socket, 0);
|
||||
rc = zmq_msg_recv (&recv_part, socket_, 0);
|
||||
assert (rc != -1);
|
||||
|
||||
rc = zmq_getsockopt (socket, ZMQ_RCVMORE, &more, &more_size);
|
||||
rc = zmq_getsockopt (socket_, ZMQ_RCVMORE, &more, &more_size);
|
||||
assert (rc == 0);
|
||||
|
||||
zmq_msg_init (&sent_part);
|
||||
zmq_msg_copy (&sent_part, &recv_part);
|
||||
|
||||
rc = zmq_msg_send (&sent_part, socket, more ? ZMQ_SNDMORE : 0);
|
||||
rc = zmq_msg_send (&sent_part, socket_, more ? ZMQ_SNDMORE : 0);
|
||||
assert (rc != -1);
|
||||
|
||||
zmq_msg_close (&recv_part);
|
||||
} while (more);
|
||||
}
|
||||
|
||||
static int get_events (void *socket)
|
||||
static int get_events (void *socket_)
|
||||
{
|
||||
int rc;
|
||||
int events;
|
||||
size_t events_size = sizeof (events);
|
||||
rc = zmq_getsockopt (socket, ZMQ_EVENTS, &events, &events_size);
|
||||
rc = zmq_getsockopt (socket_, ZMQ_EVENTS, &events, &events_size);
|
||||
assert (rc == 0);
|
||||
return events;
|
||||
}
|
||||
|
@ -40,17 +40,17 @@ void tearDown ()
|
||||
teardown_test_context ();
|
||||
}
|
||||
|
||||
void test_single_connect (int ipv6)
|
||||
void test_single_connect (int ipv6_)
|
||||
{
|
||||
size_t len = MAX_SOCKET_STRING;
|
||||
char my_endpoint[MAX_SOCKET_STRING];
|
||||
|
||||
void *sb = test_context_socket (ZMQ_REP);
|
||||
bind_loopback (sb, ipv6, my_endpoint, len);
|
||||
bind_loopback (sb, ipv6_, my_endpoint, len);
|
||||
|
||||
void *sc = test_context_socket (ZMQ_REQ);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (sc, ZMQ_IPV6, &ipv6, sizeof (int)));
|
||||
zmq_setsockopt (sc, ZMQ_IPV6, &ipv6_, sizeof (int)));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint));
|
||||
|
||||
bounce (sb, sc);
|
||||
@ -67,16 +67,16 @@ void test_single_connect (int ipv6)
|
||||
test_context_socket_close (sb);
|
||||
}
|
||||
|
||||
void make_connect_address (char *connect_address,
|
||||
const int ipv6,
|
||||
const int port,
|
||||
const char *bind_address)
|
||||
void make_connect_address (char *connect_address_,
|
||||
const int ipv6_,
|
||||
const int port_,
|
||||
const char *bind_address_)
|
||||
{
|
||||
sprintf (connect_address, "tcp://%s:%i;%s", ipv6 ? "[::1]" : "127.0.0.1",
|
||||
port, strrchr (bind_address, '/') + 1);
|
||||
sprintf (connect_address_, "tcp://%s:%i;%s", ipv6_ ? "[::1]" : "127.0.0.1",
|
||||
port_, strrchr (bind_address_, '/') + 1);
|
||||
}
|
||||
|
||||
void test_multi_connect (int ipv6)
|
||||
void test_multi_connect (int ipv6_)
|
||||
{
|
||||
size_t len = MAX_SOCKET_STRING;
|
||||
char my_endpoint_0[MAX_SOCKET_STRING];
|
||||
@ -85,20 +85,20 @@ void test_multi_connect (int ipv6)
|
||||
char my_endpoint_3[MAX_SOCKET_STRING * 2];
|
||||
|
||||
void *sb0 = test_context_socket (ZMQ_REP);
|
||||
bind_loopback (sb0, ipv6, my_endpoint_0, len);
|
||||
bind_loopback (sb0, ipv6_, my_endpoint_0, len);
|
||||
|
||||
void *sb1 = test_context_socket (ZMQ_REP);
|
||||
bind_loopback (sb1, ipv6, my_endpoint_1, len);
|
||||
bind_loopback (sb1, ipv6_, my_endpoint_1, len);
|
||||
|
||||
void *sb2 = test_context_socket (ZMQ_REP);
|
||||
bind_loopback (sb2, ipv6, my_endpoint_2, len);
|
||||
bind_loopback (sb2, ipv6_, my_endpoint_2, len);
|
||||
|
||||
void *sc = test_context_socket (ZMQ_REQ);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (sc, ZMQ_IPV6, &ipv6, sizeof (int)));
|
||||
zmq_setsockopt (sc, ZMQ_IPV6, &ipv6_, sizeof (int)));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint_0));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint_1));
|
||||
make_connect_address (my_endpoint_3, ipv6, 5564, my_endpoint_2);
|
||||
make_connect_address (my_endpoint_3, ipv6_, 5564, my_endpoint_2);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint_3));
|
||||
|
||||
bounce (sb0, sc);
|
||||
@ -125,7 +125,7 @@ void test_multi_connect (int ipv6)
|
||||
test_context_socket_close (sb2);
|
||||
}
|
||||
|
||||
void test_multi_connect_same_port (int ipv6)
|
||||
void test_multi_connect_same_port (int ipv6_)
|
||||
{
|
||||
size_t len = MAX_SOCKET_STRING;
|
||||
char my_endpoint_0[MAX_SOCKET_STRING];
|
||||
@ -136,25 +136,25 @@ void test_multi_connect_same_port (int ipv6)
|
||||
char my_endpoint_5[MAX_SOCKET_STRING * 2];
|
||||
|
||||
void *sb0 = test_context_socket (ZMQ_REP);
|
||||
bind_loopback (sb0, ipv6, my_endpoint_0, len);
|
||||
bind_loopback (sb0, ipv6_, my_endpoint_0, len);
|
||||
|
||||
void *sb1 = test_context_socket (ZMQ_REP);
|
||||
bind_loopback (sb1, ipv6, my_endpoint_1, len);
|
||||
bind_loopback (sb1, ipv6_, my_endpoint_1, len);
|
||||
|
||||
void *sc0 = test_context_socket (ZMQ_REQ);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (sc0, ZMQ_IPV6, &ipv6, sizeof (int)));
|
||||
make_connect_address (my_endpoint_2, ipv6, 5564, my_endpoint_0);
|
||||
zmq_setsockopt (sc0, ZMQ_IPV6, &ipv6_, sizeof (int)));
|
||||
make_connect_address (my_endpoint_2, ipv6_, 5564, my_endpoint_0);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc0, my_endpoint_2));
|
||||
make_connect_address (my_endpoint_3, ipv6, 5565, my_endpoint_1);
|
||||
make_connect_address (my_endpoint_3, ipv6_, 5565, my_endpoint_1);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc0, my_endpoint_3));
|
||||
|
||||
void *sc1 = test_context_socket (ZMQ_REQ);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (sc1, ZMQ_IPV6, &ipv6, sizeof (int)));
|
||||
make_connect_address (my_endpoint_4, ipv6, 5565, my_endpoint_0);
|
||||
zmq_setsockopt (sc1, ZMQ_IPV6, &ipv6_, sizeof (int)));
|
||||
make_connect_address (my_endpoint_4, ipv6_, 5565, my_endpoint_0);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc1, my_endpoint_4));
|
||||
make_connect_address (my_endpoint_5, ipv6, 5564, my_endpoint_1);
|
||||
make_connect_address (my_endpoint_5, ipv6_, 5564, my_endpoint_1);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc1, my_endpoint_5));
|
||||
|
||||
bounce (sb0, sc0);
|
||||
|
@ -43,14 +43,15 @@ void tearDown ()
|
||||
}
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
bool send_msg_to_peer_if_ready (void *router, const char *peer_routing_id)
|
||||
bool send_msg_to_peer_if_ready (void *router_, const char *peer_routing_id_)
|
||||
{
|
||||
int rc = TEST_ASSERT_SUCCESS_MESSAGE_ERRNO (
|
||||
zmq_socket_get_peer_state (router, peer_routing_id, 1), peer_routing_id);
|
||||
zmq_socket_get_peer_state (router_, peer_routing_id_, 1),
|
||||
peer_routing_id_);
|
||||
if (rc & ZMQ_POLLOUT) {
|
||||
send_string_expect_success (router, peer_routing_id,
|
||||
send_string_expect_success (router_, peer_routing_id_,
|
||||
ZMQ_SNDMORE | ZMQ_DONTWAIT);
|
||||
send_string_expect_success (router, "Hello", ZMQ_DONTWAIT);
|
||||
send_string_expect_success (router_, "Hello", ZMQ_DONTWAIT);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -87,9 +87,9 @@ int main (void)
|
||||
assert (buffer[0] == 'X');
|
||||
|
||||
int i;
|
||||
const int BUF_SIZE = 65536;
|
||||
char buf[BUF_SIZE];
|
||||
memset (buf, 0, BUF_SIZE);
|
||||
const int buf_size = 65536;
|
||||
char buf[buf_size];
|
||||
memset (buf, 0, buf_size);
|
||||
// Send first batch of messages
|
||||
for (i = 0; i < 100000; ++i) {
|
||||
if (TRACE_ENABLED)
|
||||
@ -98,8 +98,8 @@ int main (void)
|
||||
if (rc == -1 && zmq_errno () == EAGAIN)
|
||||
break;
|
||||
assert (rc == 1);
|
||||
rc = zmq_send (router, buf, BUF_SIZE, ZMQ_DONTWAIT);
|
||||
assert (rc == BUF_SIZE);
|
||||
rc = zmq_send (router, buf, buf_size, ZMQ_DONTWAIT);
|
||||
assert (rc == buf_size);
|
||||
}
|
||||
// This should fail after one message but kernel buffering could
|
||||
// skew results
|
||||
@ -113,8 +113,8 @@ int main (void)
|
||||
if (rc == -1 && zmq_errno () == EAGAIN)
|
||||
break;
|
||||
assert (rc == 1);
|
||||
rc = zmq_send (router, buf, BUF_SIZE, ZMQ_DONTWAIT);
|
||||
assert (rc == BUF_SIZE);
|
||||
rc = zmq_send (router, buf, buf_size, ZMQ_DONTWAIT);
|
||||
assert (rc == buf_size);
|
||||
}
|
||||
// This should fail after two messages but kernel buffering could
|
||||
// skew results
|
||||
|
@ -91,42 +91,43 @@ const char large_routing_id[] = "0123456789012345678901234567890123456789"
|
||||
"0123456789012345678901234567890123456789"
|
||||
"012345678901234";
|
||||
|
||||
static void zap_handler_large_routing_id (void *ctx)
|
||||
static void zap_handler_large_routing_id (void *ctx_)
|
||||
{
|
||||
zap_handler_generic (ctx, zap_ok, large_routing_id);
|
||||
zap_handler_generic (ctx_, zap_ok, large_routing_id);
|
||||
}
|
||||
|
||||
void expect_new_client_curve_bounce_fail (void *ctx,
|
||||
char *server_public,
|
||||
char *client_public,
|
||||
char *client_secret,
|
||||
char *my_endpoint,
|
||||
void *server,
|
||||
void **client_mon = NULL,
|
||||
int expected_client_event = 0,
|
||||
int expected_client_value = 0)
|
||||
void expect_new_client_curve_bounce_fail (void *ctx_,
|
||||
char *server_public_,
|
||||
char *client_public_,
|
||||
char *client_secret_,
|
||||
char *my_endpoint_,
|
||||
void *server_,
|
||||
void **client_mon_ = NULL,
|
||||
int expected_client_event_ = 0,
|
||||
int expected_client_value_ = 0)
|
||||
{
|
||||
curve_client_data_t curve_client_data = {server_public, client_public,
|
||||
client_secret};
|
||||
curve_client_data_t curve_client_data = {server_public_, client_public_,
|
||||
client_secret_};
|
||||
expect_new_client_bounce_fail (
|
||||
ctx, my_endpoint, server, socket_config_curve_client, &curve_client_data,
|
||||
client_mon, expected_client_event, expected_client_value);
|
||||
ctx_, my_endpoint_, server_, socket_config_curve_client,
|
||||
&curve_client_data, client_mon_, expected_client_event_,
|
||||
expected_client_value_);
|
||||
}
|
||||
|
||||
void test_null_key (void *ctx,
|
||||
void *server,
|
||||
void *server_mon,
|
||||
char *my_endpoint,
|
||||
char *server_public,
|
||||
char *client_public,
|
||||
char *client_secret)
|
||||
void test_null_key (void *ctx_,
|
||||
void *server_,
|
||||
void *server_mon_,
|
||||
char *my_endpoint_,
|
||||
char *server_public_,
|
||||
char *client_public_,
|
||||
char *client_secret_)
|
||||
{
|
||||
expect_new_client_curve_bounce_fail (ctx, server_public, client_public,
|
||||
client_secret, my_endpoint, server);
|
||||
expect_new_client_curve_bounce_fail (ctx_, server_public_, client_public_,
|
||||
client_secret_, my_endpoint_, server_);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
int handshake_failed_encryption_event_count =
|
||||
expect_monitor_event_multiple (server_mon,
|
||||
expect_monitor_event_multiple (server_mon_,
|
||||
ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL,
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
|
||||
|
||||
@ -201,19 +202,19 @@ void test_curve_security_with_bogus_client_credentials ()
|
||||
|| 1 <= zmq_atomic_counter_value (zap_requests_handled));
|
||||
}
|
||||
|
||||
void expect_zmtp_mechanism_mismatch (void *client,
|
||||
char *my_endpoint,
|
||||
void *server,
|
||||
void *server_mon)
|
||||
void expect_zmtp_mechanism_mismatch (void *client_,
|
||||
char *my_endpoint_,
|
||||
void *server_,
|
||||
void *server_mon_)
|
||||
{
|
||||
// This must be caught by the curve_server class, not passed to ZAP
|
||||
int rc = zmq_connect (client, my_endpoint);
|
||||
int rc = zmq_connect (client_, my_endpoint_);
|
||||
TEST_ASSERT_ZMQ_ERRNO (rc == 0);
|
||||
expect_bounce_fail (server, client);
|
||||
close_zero_linger (client);
|
||||
expect_bounce_fail (server_, client_);
|
||||
close_zero_linger (client_);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
expect_monitor_event_multiple (server_mon,
|
||||
expect_monitor_event_multiple (server_mon_,
|
||||
ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL,
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_MECHANISM_MISMATCH);
|
||||
#endif
|
||||
@ -241,13 +242,13 @@ void test_curve_security_with_plain_client_credentials ()
|
||||
expect_zmtp_mechanism_mismatch (client, my_endpoint, server, server_mon);
|
||||
}
|
||||
|
||||
fd_t connect_vanilla_socket (char *my_endpoint)
|
||||
fd_t connect_vanilla_socket (char *my_endpoint_)
|
||||
{
|
||||
fd_t s;
|
||||
struct sockaddr_in ip4addr;
|
||||
|
||||
unsigned short int port;
|
||||
int rc = sscanf (my_endpoint, "tcp://127.0.0.1:%hu", &port);
|
||||
int rc = sscanf (my_endpoint_, "tcp://127.0.0.1:%hu", &port);
|
||||
TEST_ASSERT_EQUAL_INT (1, rc);
|
||||
|
||||
ip4addr.sin_family = AF_INET;
|
||||
@ -279,28 +280,28 @@ void test_curve_security_unauthenticated_message ()
|
||||
close (s);
|
||||
}
|
||||
|
||||
void send_all (fd_t fd, const char *data, socket_size_t size)
|
||||
void send_all (fd_t fd_, const char *data_, socket_size_t size_)
|
||||
{
|
||||
while (size > 0) {
|
||||
int res = send (fd, data, size, 0);
|
||||
while (size_ > 0) {
|
||||
int res = send (fd_, data_, size_, 0);
|
||||
TEST_ASSERT_GREATER_THAN_INT (0, res);
|
||||
size -= res;
|
||||
data += res;
|
||||
size_ -= res;
|
||||
data_ += res;
|
||||
}
|
||||
}
|
||||
|
||||
template <size_t N> void send (fd_t fd, const char (&data)[N])
|
||||
template <size_t N> void send (fd_t fd_, const char (&data_)[N])
|
||||
{
|
||||
send_all (fd, data, N - 1);
|
||||
send_all (fd_, data_, N - 1);
|
||||
}
|
||||
|
||||
void send_greeting (fd_t s)
|
||||
void send_greeting (fd_t s_)
|
||||
{
|
||||
send (s, "\xff\0\0\0\0\0\0\0\0\x7f"); // signature
|
||||
send (s, "\x03\x00"); // version 3.0
|
||||
send (s, "CURVE\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); // mechanism CURVE
|
||||
send (s, "\0"); // as-server == false
|
||||
send (s, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
|
||||
send (s_, "\xff\0\0\0\0\0\0\0\0\x7f"); // signature
|
||||
send (s_, "\x03\x00"); // version 3.0
|
||||
send (s_, "CURVE\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); // mechanism CURVE
|
||||
send (s_, "\0"); // as-server == false
|
||||
send (s_, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
|
||||
}
|
||||
|
||||
void test_curve_security_invalid_hello_wrong_length ()
|
||||
@ -342,36 +343,36 @@ zmq::curve_client_tools_t make_curve_client_tools ()
|
||||
}
|
||||
|
||||
#ifndef htonll
|
||||
uint64_t htonll (uint64_t value)
|
||||
uint64_t htonll (uint64_t value_)
|
||||
{
|
||||
// The answer is 42
|
||||
static const int num = 42;
|
||||
|
||||
// Check the endianness
|
||||
if (*reinterpret_cast<const char *> (&num) == num) {
|
||||
const uint32_t high_part = htonl (static_cast<uint32_t> (value >> 32));
|
||||
const uint32_t high_part = htonl (static_cast<uint32_t> (value_ >> 32));
|
||||
const uint32_t low_part =
|
||||
htonl (static_cast<uint32_t> (value & 0xFFFFFFFFLL));
|
||||
htonl (static_cast<uint32_t> (value_ & 0xFFFFFFFFLL));
|
||||
|
||||
return (static_cast<uint64_t> (low_part) << 32) | high_part;
|
||||
} else {
|
||||
return value;
|
||||
return value_;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
template <size_t N> void send_command (fd_t s, char (&command)[N])
|
||||
template <size_t N> void send_command (fd_t s_, char (&command_)[N])
|
||||
{
|
||||
if (N < 256) {
|
||||
send (s, "\x04");
|
||||
send (s_, "\x04");
|
||||
char len = (char) N;
|
||||
send_all (s, &len, 1);
|
||||
send_all (s_, &len, 1);
|
||||
} else {
|
||||
send (s, "\x06");
|
||||
send (s_, "\x06");
|
||||
uint64_t len = htonll (N);
|
||||
send_all (s, (char *) &len, 8);
|
||||
send_all (s_, (char *) &len, 8);
|
||||
}
|
||||
send_all (s, command, N);
|
||||
send_all (s_, command_, N);
|
||||
}
|
||||
|
||||
void test_curve_security_invalid_hello_command_name ()
|
||||
@ -424,46 +425,46 @@ void test_curve_security_invalid_hello_version ()
|
||||
close (s);
|
||||
}
|
||||
|
||||
void flush_read (fd_t fd)
|
||||
void flush_read (fd_t fd_)
|
||||
{
|
||||
int res;
|
||||
char buf[256];
|
||||
|
||||
while ((res = recv (fd, buf, 256, 0)) == 256) {
|
||||
while ((res = recv (fd_, buf, 256, 0)) == 256) {
|
||||
}
|
||||
TEST_ASSERT_NOT_EQUAL (-1, res);
|
||||
}
|
||||
|
||||
void recv_all (fd_t fd, uint8_t *data, socket_size_t len)
|
||||
void recv_all (fd_t fd_, uint8_t *data_, socket_size_t len_)
|
||||
{
|
||||
socket_size_t received = 0;
|
||||
while (received < len) {
|
||||
int res = recv (fd, (char *) data, len, 0);
|
||||
while (received < len_) {
|
||||
int res = recv (fd_, (char *) data_, len_, 0);
|
||||
TEST_ASSERT_GREATER_THAN_INT (0, res);
|
||||
|
||||
data += res;
|
||||
data_ += res;
|
||||
received += res;
|
||||
}
|
||||
}
|
||||
|
||||
void recv_greeting (fd_t fd)
|
||||
void recv_greeting (fd_t fd_)
|
||||
{
|
||||
uint8_t greeting[64];
|
||||
recv_all (fd, greeting, 64);
|
||||
recv_all (fd_, greeting, 64);
|
||||
// TODO assert anything about the greeting received from the server?
|
||||
}
|
||||
|
||||
fd_t connect_exchange_greeting_and_send_hello (char *my_endpoint,
|
||||
zmq::curve_client_tools_t &tools)
|
||||
fd_t connect_exchange_greeting_and_send_hello (
|
||||
char *my_endpoint_, zmq::curve_client_tools_t &tools_)
|
||||
{
|
||||
fd_t s = connect_vanilla_socket (my_endpoint);
|
||||
fd_t s = connect_vanilla_socket (my_endpoint_);
|
||||
|
||||
send_greeting (s);
|
||||
recv_greeting (s);
|
||||
|
||||
// send valid CURVE HELLO
|
||||
char hello[hello_length];
|
||||
int rc = tools.produce_hello (hello, 0);
|
||||
int rc = tools_.produce_hello (hello, 0);
|
||||
TEST_ASSERT_ZMQ_ERRNO (rc == 0);
|
||||
|
||||
send_command (s, hello);
|
||||
@ -498,23 +499,23 @@ void test_curve_security_invalid_initiate_wrong_length ()
|
||||
}
|
||||
|
||||
fd_t connect_exchange_greeting_and_hello_welcome (
|
||||
char *my_endpoint,
|
||||
void *server_mon,
|
||||
int timeout,
|
||||
zmq::curve_client_tools_t &tools)
|
||||
char *my_endpoint_,
|
||||
void *server_mon_,
|
||||
int timeout_,
|
||||
zmq::curve_client_tools_t &tools_)
|
||||
{
|
||||
fd_t s = connect_exchange_greeting_and_send_hello (my_endpoint, tools);
|
||||
fd_t s = connect_exchange_greeting_and_send_hello (my_endpoint_, tools_);
|
||||
|
||||
// receive but ignore WELCOME
|
||||
uint8_t welcome[welcome_length + 2];
|
||||
recv_all (s, welcome, welcome_length + 2);
|
||||
|
||||
uint8_t cn_precom[crypto_box_BEFORENMBYTES];
|
||||
int res = tools.process_welcome (welcome + 2, welcome_length, cn_precom);
|
||||
int res = tools_.process_welcome (welcome + 2, welcome_length, cn_precom);
|
||||
TEST_ASSERT_ZMQ_ERRNO (res == 0);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
res = get_monitor_event_with_timeout (server_mon, NULL, NULL, timeout);
|
||||
res = get_monitor_event_with_timeout (server_mon_, NULL, NULL, timeout_);
|
||||
TEST_ASSERT_EQUAL_INT (-1, res);
|
||||
#endif
|
||||
|
||||
@ -587,10 +588,10 @@ void test_curve_security_invalid_initiate_command_encrypted_content ()
|
||||
close (s);
|
||||
}
|
||||
|
||||
void test_curve_security_invalid_keysize (void *ctx)
|
||||
void test_curve_security_invalid_keysize (void *ctx_)
|
||||
{
|
||||
// Check return codes for invalid buffer sizes
|
||||
void *client = zmq_socket (ctx, ZMQ_DEALER);
|
||||
void *client = zmq_socket (ctx_, ZMQ_DEALER);
|
||||
TEST_ASSERT_NOT_NULL (client);
|
||||
errno = 0;
|
||||
int rc =
|
||||
|
@ -60,33 +60,33 @@ static volatile int zap_deny_all = 0;
|
||||
// in case of error.
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
static int get_monitor_event (void *monitor, int *value, char **address)
|
||||
static int get_monitor_event (void *monitor_, int *value_, char **address_)
|
||||
{
|
||||
// First frame in message contains event number and value
|
||||
zmq_msg_t msg;
|
||||
zmq_msg_init (&msg);
|
||||
if (zmq_msg_recv (&msg, monitor, 0) == -1)
|
||||
if (zmq_msg_recv (&msg, monitor_, 0) == -1)
|
||||
return -1; // Interruped, presumably
|
||||
assert (zmq_msg_more (&msg));
|
||||
|
||||
uint8_t *data = (uint8_t *) zmq_msg_data (&msg);
|
||||
uint16_t event = *(uint16_t *) (data);
|
||||
if (value)
|
||||
*value = *(uint32_t *) (data + 2);
|
||||
if (value_)
|
||||
*value_ = *(uint32_t *) (data + 2);
|
||||
zmq_msg_close (&msg);
|
||||
|
||||
// Second frame in message contains event address
|
||||
zmq_msg_init (&msg);
|
||||
if (zmq_msg_recv (&msg, monitor, 0) == -1)
|
||||
if (zmq_msg_recv (&msg, monitor_, 0) == -1)
|
||||
return -1; // Interruped, presumably
|
||||
assert (!zmq_msg_more (&msg));
|
||||
|
||||
if (address) {
|
||||
if (address_) {
|
||||
uint8_t *data = (uint8_t *) zmq_msg_data (&msg);
|
||||
size_t size = zmq_msg_size (&msg);
|
||||
*address = (char *) malloc (size + 1);
|
||||
memcpy (*address, data, size);
|
||||
*address[size] = 0;
|
||||
*address_ = (char *) malloc (size + 1);
|
||||
memcpy (*address_, data, size);
|
||||
*address_[size] = 0;
|
||||
}
|
||||
zmq_msg_close (&msg);
|
||||
|
||||
@ -99,38 +99,38 @@ static int get_monitor_event (void *monitor, int *value, char **address)
|
||||
// each client connection).
|
||||
// N.B. on failure, each crypto type in keytab will be tried
|
||||
|
||||
static void zap_handler (void *handler)
|
||||
static void zap_handler (void *handler_)
|
||||
{
|
||||
// Process ZAP requests forever
|
||||
while (true) {
|
||||
char *version = s_recv (handler);
|
||||
char *version = s_recv (handler_);
|
||||
if (!version)
|
||||
break; // Terminating
|
||||
|
||||
char *sequence = s_recv (handler);
|
||||
char *domain = s_recv (handler);
|
||||
char *address = s_recv (handler);
|
||||
char *routing_id = s_recv (handler);
|
||||
char *mechanism = s_recv (handler);
|
||||
char *principal = s_recv (handler);
|
||||
char *sequence = s_recv (handler_);
|
||||
char *domain = s_recv (handler_);
|
||||
char *address = s_recv (handler_);
|
||||
char *routing_id = s_recv (handler_);
|
||||
char *mechanism = s_recv (handler_);
|
||||
char *principal = s_recv (handler_);
|
||||
|
||||
assert (streq (version, "1.0"));
|
||||
assert (streq (mechanism, "GSSAPI"));
|
||||
|
||||
s_sendmore (handler, version);
|
||||
s_sendmore (handler, sequence);
|
||||
s_sendmore (handler_, version);
|
||||
s_sendmore (handler_, sequence);
|
||||
|
||||
if (!zap_deny_all) {
|
||||
s_sendmore (handler, "200");
|
||||
s_sendmore (handler, "OK");
|
||||
s_sendmore (handler, "anonymous");
|
||||
s_send (handler, "");
|
||||
s_sendmore (handler_, "200");
|
||||
s_sendmore (handler_, "OK");
|
||||
s_sendmore (handler_, "anonymous");
|
||||
s_send (handler_, "");
|
||||
//fprintf (stderr, "ALLOW %s\n", principal);
|
||||
} else {
|
||||
s_sendmore (handler, "400");
|
||||
s_sendmore (handler, "Denied");
|
||||
s_sendmore (handler, "");
|
||||
s_send (handler, "");
|
||||
s_sendmore (handler_, "400");
|
||||
s_sendmore (handler_, "Denied");
|
||||
s_sendmore (handler_, "");
|
||||
s_send (handler_, "");
|
||||
//fprintf (stderr, "DENY %s\n", principal);
|
||||
}
|
||||
free (version);
|
||||
@ -141,15 +141,15 @@ static void zap_handler (void *handler)
|
||||
free (mechanism);
|
||||
free (principal);
|
||||
}
|
||||
zmq_close (handler);
|
||||
zmq_close (handler_);
|
||||
}
|
||||
|
||||
void test_valid_creds (void *ctx,
|
||||
void *server,
|
||||
void *server_mon,
|
||||
char *endpoint)
|
||||
void test_valid_creds (void *ctx_,
|
||||
void *server_,
|
||||
void *server_mon_,
|
||||
char *endpoint_)
|
||||
{
|
||||
void *client = zmq_socket (ctx, ZMQ_DEALER);
|
||||
void *client = zmq_socket (ctx_, ZMQ_DEALER);
|
||||
assert (client);
|
||||
int rc = zmq_setsockopt (client, ZMQ_GSSAPI_SERVICE_PRINCIPAL, name,
|
||||
strlen (name) + 1);
|
||||
@ -160,15 +160,15 @@ void test_valid_creds (void *ctx,
|
||||
rc = zmq_setsockopt (client, ZMQ_GSSAPI_PRINCIPAL_NAMETYPE, &name_type,
|
||||
sizeof (name_type));
|
||||
assert (rc == 0);
|
||||
rc = zmq_connect (client, endpoint);
|
||||
rc = zmq_connect (client, endpoint_);
|
||||
assert (rc == 0);
|
||||
|
||||
bounce (server, client);
|
||||
bounce (server_, client);
|
||||
rc = zmq_close (client);
|
||||
assert (rc == 0);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
int event = get_monitor_event (server_mon, NULL, NULL);
|
||||
int event = get_monitor_event (server_mon_, NULL, NULL);
|
||||
assert (event == ZMQ_EVENT_HANDSHAKE_SUCCEEDED);
|
||||
#endif
|
||||
}
|
||||
@ -176,12 +176,12 @@ void test_valid_creds (void *ctx,
|
||||
// Check security with valid but unauthorized credentials
|
||||
// Note: ZAP may see multiple requests - after a failure, client will
|
||||
// fall back to other crypto types for principal, if available.
|
||||
void test_unauth_creds (void *ctx,
|
||||
void *server,
|
||||
void *server_mon,
|
||||
char *endpoint)
|
||||
void test_unauth_creds (void *ctx_,
|
||||
void *server_,
|
||||
void *server_mon_,
|
||||
char *endpoint_)
|
||||
{
|
||||
void *client = zmq_socket (ctx, ZMQ_DEALER);
|
||||
void *client = zmq_socket (ctx_, ZMQ_DEALER);
|
||||
assert (client);
|
||||
int rc = zmq_setsockopt (client, ZMQ_GSSAPI_SERVICE_PRINCIPAL, name,
|
||||
strlen (name) + 1);
|
||||
@ -193,32 +193,35 @@ void test_unauth_creds (void *ctx,
|
||||
sizeof (name_type));
|
||||
assert (rc == 0);
|
||||
zap_deny_all = 1;
|
||||
rc = zmq_connect (client, endpoint);
|
||||
rc = zmq_connect (client, endpoint_);
|
||||
assert (rc == 0);
|
||||
|
||||
expect_bounce_fail (server, client);
|
||||
expect_bounce_fail (server_, client);
|
||||
close_zero_linger (client);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
int event = get_monitor_event (server_mon, NULL, NULL);
|
||||
int event = get_monitor_event (server_mon_, NULL, NULL);
|
||||
assert (event == ZMQ_EVENT_HANDSHAKE_FAILED_AUTH);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Check GSSAPI security with NULL client credentials
|
||||
// This must be caught by the gssapi_server class, not passed to ZAP
|
||||
void test_null_creds (void *ctx, void *server, void *server_mon, char *endpoint)
|
||||
void test_null_creds (void *ctx_,
|
||||
void *server_,
|
||||
void *server_mon_,
|
||||
char *endpoint_)
|
||||
{
|
||||
void *client = zmq_socket (ctx, ZMQ_DEALER);
|
||||
void *client = zmq_socket (ctx_, ZMQ_DEALER);
|
||||
assert (client);
|
||||
int rc = zmq_connect (client, endpoint);
|
||||
int rc = zmq_connect (client, endpoint_);
|
||||
assert (rc == 0);
|
||||
expect_bounce_fail (server, client);
|
||||
expect_bounce_fail (server_, client);
|
||||
close_zero_linger (client);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
int error;
|
||||
int event = get_monitor_event (server_mon, &error, NULL);
|
||||
int event = get_monitor_event (server_mon_, &error, NULL);
|
||||
assert (event == ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL);
|
||||
assert (error == ZMQ_PROTOCOL_ERROR_ZMTP_MECHANISM_MISMATCH);
|
||||
#endif
|
||||
@ -226,33 +229,33 @@ void test_null_creds (void *ctx, void *server, void *server_mon, char *endpoint)
|
||||
|
||||
// Check GSSAPI security with PLAIN client credentials
|
||||
// This must be caught by the curve_server class, not passed to ZAP
|
||||
void test_plain_creds (void *ctx,
|
||||
void *server,
|
||||
void *server_mon,
|
||||
char *endpoint)
|
||||
void test_plain_creds (void *ctx_,
|
||||
void *server_,
|
||||
void *server_mon_,
|
||||
char *endpoint_)
|
||||
{
|
||||
void *client = zmq_socket (ctx, ZMQ_DEALER);
|
||||
void *client = zmq_socket (ctx_, ZMQ_DEALER);
|
||||
assert (client);
|
||||
int rc = zmq_setsockopt (client, ZMQ_PLAIN_USERNAME, "admin", 5);
|
||||
assert (rc == 0);
|
||||
rc = zmq_setsockopt (client, ZMQ_PLAIN_PASSWORD, "password", 8);
|
||||
assert (rc == 0);
|
||||
rc = zmq_connect (client, endpoint);
|
||||
rc = zmq_connect (client, endpoint_);
|
||||
assert (rc == 0);
|
||||
expect_bounce_fail (server, client);
|
||||
expect_bounce_fail (server_, client);
|
||||
close_zero_linger (client);
|
||||
}
|
||||
|
||||
// Unauthenticated messages from a vanilla socket shouldn't be received
|
||||
void test_vanilla_socket (void *ctx,
|
||||
void *server,
|
||||
void *server_mon,
|
||||
char *endpoint)
|
||||
void test_vanilla_socket (void *ctx_,
|
||||
void *server_,
|
||||
void *server_mon_,
|
||||
char *endpoint_)
|
||||
{
|
||||
struct sockaddr_in ip4addr;
|
||||
int s;
|
||||
unsigned short int port;
|
||||
int rc = sscanf (endpoint, "tcp://127.0.0.1:%hu", &port);
|
||||
int rc = sscanf (endpoint_, "tcp://127.0.0.1:%hu", &port);
|
||||
assert (rc == 1);
|
||||
ip4addr.sin_family = AF_INET;
|
||||
ip4addr.sin_port = htons (port);
|
||||
@ -270,8 +273,8 @@ void test_vanilla_socket (void *ctx,
|
||||
// send sneaky message that shouldn't be received
|
||||
send (s, "\x08\x00sneaky\0", 9, 0);
|
||||
int timeout = 250;
|
||||
zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof (timeout));
|
||||
char *buf = s_recv (server);
|
||||
zmq_setsockopt (server_, ZMQ_RCVTIMEO, &timeout, sizeof (timeout));
|
||||
char *buf = s_recv (server_);
|
||||
if (buf != NULL) {
|
||||
printf ("Received unauthenticated message: %s\n", buf);
|
||||
assert (buf == NULL);
|
||||
|
@ -40,35 +40,35 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
static void zap_handler (void *handler)
|
||||
static void zap_handler (void *handler_)
|
||||
{
|
||||
// Process ZAP requests forever
|
||||
while (true) {
|
||||
char *version = s_recv (handler);
|
||||
char *version = s_recv (handler_);
|
||||
if (!version)
|
||||
break; // Terminating
|
||||
|
||||
char *sequence = s_recv (handler);
|
||||
char *domain = s_recv (handler);
|
||||
char *address = s_recv (handler);
|
||||
char *routing_id = s_recv (handler);
|
||||
char *mechanism = s_recv (handler);
|
||||
char *sequence = s_recv (handler_);
|
||||
char *domain = s_recv (handler_);
|
||||
char *address = s_recv (handler_);
|
||||
char *routing_id = s_recv (handler_);
|
||||
char *mechanism = s_recv (handler_);
|
||||
|
||||
assert (streq (version, "1.0"));
|
||||
assert (streq (mechanism, "NULL"));
|
||||
|
||||
s_sendmore (handler, version);
|
||||
s_sendmore (handler, sequence);
|
||||
s_sendmore (handler_, version);
|
||||
s_sendmore (handler_, sequence);
|
||||
if (streq (domain, "TEST")) {
|
||||
s_sendmore (handler, "200");
|
||||
s_sendmore (handler, "OK");
|
||||
s_sendmore (handler, "anonymous");
|
||||
s_send (handler, "");
|
||||
s_sendmore (handler_, "200");
|
||||
s_sendmore (handler_, "OK");
|
||||
s_sendmore (handler_, "anonymous");
|
||||
s_send (handler_, "");
|
||||
} else {
|
||||
s_sendmore (handler, "400");
|
||||
s_sendmore (handler, "BAD DOMAIN");
|
||||
s_sendmore (handler, "");
|
||||
s_send (handler, "");
|
||||
s_sendmore (handler_, "400");
|
||||
s_sendmore (handler_, "BAD DOMAIN");
|
||||
s_sendmore (handler_, "");
|
||||
s_send (handler_, "");
|
||||
}
|
||||
free (version);
|
||||
free (sequence);
|
||||
@ -77,7 +77,7 @@ static void zap_handler (void *handler)
|
||||
free (routing_id);
|
||||
free (mechanism);
|
||||
}
|
||||
close_zero_linger (handler);
|
||||
close_zero_linger (handler_);
|
||||
}
|
||||
|
||||
int main (void)
|
||||
|
@ -40,10 +40,10 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
static void zap_handler (void *ctx)
|
||||
static void zap_handler (void *ctx_)
|
||||
{
|
||||
// Create and bind ZAP socket
|
||||
void *zap = zmq_socket (ctx, ZMQ_REP);
|
||||
void *zap = zmq_socket (ctx_, ZMQ_REP);
|
||||
assert (zap);
|
||||
int rc = zmq_bind (zap, "inproc://zeromq.zap.01");
|
||||
assert (rc == 0);
|
||||
|
@ -29,94 +29,94 @@
|
||||
|
||||
#include "testutil_security.hpp"
|
||||
|
||||
static void zap_handler_wrong_version (void *ctx)
|
||||
static void zap_handler_wrong_version (void *ctx_)
|
||||
{
|
||||
zap_handler_generic (ctx, zap_wrong_version);
|
||||
zap_handler_generic (ctx_, zap_wrong_version);
|
||||
}
|
||||
|
||||
static void zap_handler_wrong_request_id (void *ctx)
|
||||
static void zap_handler_wrong_request_id (void *ctx_)
|
||||
{
|
||||
zap_handler_generic (ctx, zap_wrong_request_id);
|
||||
zap_handler_generic (ctx_, zap_wrong_request_id);
|
||||
}
|
||||
|
||||
static void zap_handler_wrong_status_invalid (void *ctx)
|
||||
static void zap_handler_wrong_status_invalid (void *ctx_)
|
||||
{
|
||||
zap_handler_generic (ctx, zap_status_invalid);
|
||||
zap_handler_generic (ctx_, zap_status_invalid);
|
||||
}
|
||||
|
||||
static void zap_handler_wrong_status_temporary_failure (void *ctx)
|
||||
static void zap_handler_wrong_status_temporary_failure (void *ctx_)
|
||||
{
|
||||
zap_handler_generic (ctx, zap_status_temporary_failure);
|
||||
zap_handler_generic (ctx_, zap_status_temporary_failure);
|
||||
}
|
||||
|
||||
static void zap_handler_wrong_status_internal_error (void *ctx)
|
||||
static void zap_handler_wrong_status_internal_error (void *ctx_)
|
||||
{
|
||||
zap_handler_generic (ctx, zap_status_internal_error);
|
||||
zap_handler_generic (ctx_, zap_status_internal_error);
|
||||
}
|
||||
|
||||
static void zap_handler_too_many_parts (void *ctx)
|
||||
static void zap_handler_too_many_parts (void *ctx_)
|
||||
{
|
||||
zap_handler_generic (ctx, zap_too_many_parts);
|
||||
zap_handler_generic (ctx_, zap_too_many_parts);
|
||||
}
|
||||
|
||||
static void zap_handler_disconnect (void *ctx)
|
||||
static void zap_handler_disconnect (void *ctx_)
|
||||
{
|
||||
zap_handler_generic (ctx, zap_disconnect);
|
||||
zap_handler_generic (ctx_, zap_disconnect);
|
||||
}
|
||||
|
||||
static void zap_handler_do_not_recv (void *ctx)
|
||||
static void zap_handler_do_not_recv (void *ctx_)
|
||||
{
|
||||
zap_handler_generic (ctx, zap_do_not_recv);
|
||||
zap_handler_generic (ctx_, zap_do_not_recv);
|
||||
}
|
||||
|
||||
static void zap_handler_do_not_send (void *ctx)
|
||||
static void zap_handler_do_not_send (void *ctx_)
|
||||
{
|
||||
zap_handler_generic (ctx, zap_do_not_send);
|
||||
zap_handler_generic (ctx_, zap_do_not_send);
|
||||
}
|
||||
|
||||
int expect_new_client_bounce_fail_and_count_monitor_events (
|
||||
void *ctx,
|
||||
char *my_endpoint,
|
||||
void *server,
|
||||
void *ctx_,
|
||||
char *my_endpoint_,
|
||||
void *server_,
|
||||
socket_config_fn socket_config_,
|
||||
void *socket_config_data_,
|
||||
void **client_mon,
|
||||
void *server_mon,
|
||||
int expected_server_event,
|
||||
int expected_server_value,
|
||||
int expected_client_event = 0,
|
||||
int expected_client_value = 0)
|
||||
void **client_mon_,
|
||||
void *server_mon_,
|
||||
int expected_server_event_,
|
||||
int expected_server_value_,
|
||||
int expected_client_event_ = 0,
|
||||
int expected_client_value_ = 0)
|
||||
{
|
||||
expect_new_client_bounce_fail (
|
||||
ctx, my_endpoint, server, socket_config_, socket_config_data_, client_mon,
|
||||
expected_client_event, expected_client_value);
|
||||
ctx_, my_endpoint_, server_, socket_config_, socket_config_data_,
|
||||
client_mon_, expected_client_event_, expected_client_value_);
|
||||
|
||||
int events_received = 0;
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
events_received = expect_monitor_event_multiple (
|
||||
server_mon, expected_server_event, expected_server_value);
|
||||
server_mon_, expected_server_event_, expected_server_value_);
|
||||
#endif
|
||||
|
||||
return events_received;
|
||||
}
|
||||
|
||||
void test_zap_unsuccessful (void *ctx,
|
||||
char *my_endpoint,
|
||||
void *server,
|
||||
void *server_mon,
|
||||
int expected_server_event,
|
||||
int expected_server_value,
|
||||
void test_zap_unsuccessful (void *ctx_,
|
||||
char *my_endpoint_,
|
||||
void *server_,
|
||||
void *server_mon_,
|
||||
int expected_server_event_,
|
||||
int expected_server_value_,
|
||||
socket_config_fn socket_config_,
|
||||
void *socket_config_data_,
|
||||
void **client_mon = NULL,
|
||||
int expected_client_event = 0,
|
||||
int expected_client_value = 0)
|
||||
void **client_mon_ = NULL,
|
||||
int expected_client_event_ = 0,
|
||||
int expected_client_value_ = 0)
|
||||
{
|
||||
int server_events_received =
|
||||
expect_new_client_bounce_fail_and_count_monitor_events (
|
||||
ctx, my_endpoint, server, socket_config_, socket_config_data_,
|
||||
client_mon, server_mon, expected_server_event, expected_server_value,
|
||||
expected_client_event, expected_client_value);
|
||||
ctx_, my_endpoint_, server_, socket_config_, socket_config_data_,
|
||||
client_mon_, server_mon_, expected_server_event_,
|
||||
expected_server_value_, expected_client_event_, expected_client_value_);
|
||||
|
||||
// there may be more than one ZAP request due to repeated attempts by the
|
||||
// client (actually only in case if ZAP status code 300)
|
||||
@ -124,20 +124,20 @@ void test_zap_unsuccessful (void *ctx,
|
||||
|| 1 <= zmq_atomic_counter_value (zap_requests_handled));
|
||||
}
|
||||
|
||||
void test_zap_unsuccessful_no_handler (void *ctx,
|
||||
char *my_endpoint,
|
||||
void *server,
|
||||
void *server_mon,
|
||||
int expected_event,
|
||||
int expected_err,
|
||||
void test_zap_unsuccessful_no_handler (void *ctx_,
|
||||
char *my_endpoint_,
|
||||
void *server_,
|
||||
void *server_mon_,
|
||||
int expected_event_,
|
||||
int expected_err_,
|
||||
socket_config_fn socket_config_,
|
||||
void *socket_config_data_,
|
||||
void **client_mon = NULL)
|
||||
void **client_mon_ = NULL)
|
||||
{
|
||||
int events_received =
|
||||
expect_new_client_bounce_fail_and_count_monitor_events (
|
||||
ctx, my_endpoint, server, socket_config_, socket_config_data_,
|
||||
client_mon, server_mon, expected_event, expected_err);
|
||||
ctx_, my_endpoint_, server_, socket_config_, socket_config_data_,
|
||||
client_mon_, server_mon_, expected_event_, expected_err_);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
// there may be more than one ZAP request due to repeated attempts by the
|
||||
@ -148,32 +148,32 @@ void test_zap_unsuccessful_no_handler (void *ctx,
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_zap_protocol_error (void *ctx,
|
||||
char *my_endpoint,
|
||||
void *server,
|
||||
void *server_mon,
|
||||
void test_zap_protocol_error (void *ctx_,
|
||||
char *my_endpoint_,
|
||||
void *server_,
|
||||
void *server_mon_,
|
||||
socket_config_fn socket_config_,
|
||||
void *socket_config_data_,
|
||||
int expected_error)
|
||||
int expected_error_)
|
||||
{
|
||||
test_zap_unsuccessful (ctx, my_endpoint, server, server_mon,
|
||||
test_zap_unsuccessful (ctx_, my_endpoint_, server_, server_mon_,
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, expected_error,
|
||||
ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, expected_error_,
|
||||
#else
|
||||
0, 0,
|
||||
#endif
|
||||
socket_config_, socket_config_data_);
|
||||
}
|
||||
|
||||
void test_zap_unsuccessful_status_300 (void *ctx,
|
||||
char *my_endpoint,
|
||||
void *server,
|
||||
void *server_mon,
|
||||
void test_zap_unsuccessful_status_300 (void *ctx_,
|
||||
char *my_endpoint_,
|
||||
void *server_,
|
||||
void *server_mon_,
|
||||
socket_config_fn client_socket_config_,
|
||||
void *client_socket_config_data_)
|
||||
{
|
||||
void *client_mon;
|
||||
test_zap_unsuccessful (ctx, my_endpoint, server, server_mon,
|
||||
test_zap_unsuccessful (ctx_, my_endpoint_, server_, server_mon_,
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, 300,
|
||||
#else
|
||||
@ -191,14 +191,14 @@ void test_zap_unsuccessful_status_300 (void *ctx,
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_zap_unsuccessful_status_500 (void *ctx,
|
||||
char *my_endpoint,
|
||||
void *server,
|
||||
void *server_mon,
|
||||
void test_zap_unsuccessful_status_500 (void *ctx_,
|
||||
char *my_endpoint_,
|
||||
void *server_,
|
||||
void *server_mon_,
|
||||
socket_config_fn client_socket_config_,
|
||||
void *client_socket_config_data_)
|
||||
{
|
||||
test_zap_unsuccessful (ctx, my_endpoint, server, server_mon,
|
||||
test_zap_unsuccessful (ctx_, my_endpoint_, server_, server_mon_,
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, 500,
|
||||
#else
|
||||
|
@ -38,11 +38,11 @@ struct thread_data
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
static void worker (void *data)
|
||||
static void worker (void *data_)
|
||||
{
|
||||
int rc;
|
||||
void *socket;
|
||||
struct thread_data *tdata = (struct thread_data *) data;
|
||||
struct thread_data *tdata = (struct thread_data *) data_;
|
||||
|
||||
socket = zmq_socket (tdata->ctx, ZMQ_SUB);
|
||||
assert (socket);
|
||||
|
@ -32,15 +32,15 @@
|
||||
#define THREAD_COUNT 100
|
||||
|
||||
extern "C" {
|
||||
static void *worker (void *s)
|
||||
static void *worker (void *s_)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = zmq_connect (s, "tipc://{5560,0}@0.0.0");
|
||||
rc = zmq_connect (s_, "tipc://{5560,0}@0.0.0");
|
||||
assert (rc == 0);
|
||||
|
||||
// Start closing the socket while the connecting process is underway.
|
||||
rc = zmq_close (s);
|
||||
rc = zmq_close (s_);
|
||||
assert (rc == 0);
|
||||
|
||||
return NULL;
|
||||
|
@ -114,23 +114,23 @@ void test_change_after_connected ()
|
||||
test_context_socket_close (connect_socket);
|
||||
}
|
||||
|
||||
int send_until_wouldblock (void *socket)
|
||||
int send_until_wouldblock (void *socket_)
|
||||
{
|
||||
int send_count = 0;
|
||||
while (send_count < MAX_SENDS
|
||||
&& zmq_send (socket, &send_count, sizeof (send_count), ZMQ_DONTWAIT)
|
||||
&& zmq_send (socket_, &send_count, sizeof (send_count), ZMQ_DONTWAIT)
|
||||
== sizeof (send_count)) {
|
||||
++send_count;
|
||||
}
|
||||
return send_count;
|
||||
}
|
||||
|
||||
int test_fill_up_to_hwm (void *socket, int sndhwm)
|
||||
int test_fill_up_to_hwm (void *socket_, int sndhwm_)
|
||||
{
|
||||
int send_count = send_until_wouldblock (socket);
|
||||
fprintf (stderr, "sndhwm==%i, send_count==%i\n", sndhwm, send_count);
|
||||
TEST_ASSERT_LESS_OR_EQUAL_INT (sndhwm + 1, send_count);
|
||||
TEST_ASSERT_GREATER_THAN_INT (sndhwm / 10, send_count);
|
||||
int send_count = send_until_wouldblock (socket_);
|
||||
fprintf (stderr, "sndhwm==%i, send_count==%i\n", sndhwm_, send_count);
|
||||
TEST_ASSERT_LESS_OR_EQUAL_INT (sndhwm_ + 1, send_count);
|
||||
TEST_ASSERT_GREATER_THAN_INT (sndhwm_ / 10, send_count);
|
||||
return send_count;
|
||||
}
|
||||
|
||||
|
@ -69,12 +69,12 @@ void test__zmq_curve_public__valid__success ()
|
||||
}
|
||||
|
||||
// The key length must be evenly divisible by 5 or must fail with EINVAL.
|
||||
void test__zmq_curve_public__invalid__failure (const char *secret)
|
||||
void test__zmq_curve_public__invalid__failure (const char *secret_)
|
||||
{
|
||||
errno = 0;
|
||||
char out_public[41] = {0};
|
||||
|
||||
const int rc = zmq_curve_public (out_public, secret);
|
||||
const int rc = zmq_curve_public (out_public, secret_);
|
||||
|
||||
#if defined(ZMQ_HAVE_CURVE)
|
||||
assert (rc == -1);
|
||||
|
@ -43,12 +43,13 @@ void tearDown ()
|
||||
|
||||
// SHALL route outgoing messages to available peers using a round-robin
|
||||
// strategy.
|
||||
void test_round_robin_out (const char *bind_address)
|
||||
void test_round_robin_out (const char *bind_address_)
|
||||
{
|
||||
void *dealer = test_context_socket (ZMQ_DEALER);
|
||||
|
||||
char connect_address[MAX_SOCKET_STRING];
|
||||
test_bind (dealer, bind_address, connect_address, sizeof (connect_address));
|
||||
test_bind (dealer, bind_address_, connect_address,
|
||||
sizeof (connect_address));
|
||||
|
||||
const size_t services = 5;
|
||||
void *rep[services];
|
||||
@ -86,7 +87,7 @@ void test_round_robin_out (const char *bind_address)
|
||||
|
||||
// SHALL receive incoming messages from its peers using a fair-queuing
|
||||
// strategy.
|
||||
void test_fair_queue_in (const char *bind_address)
|
||||
void test_fair_queue_in (const char *bind_address_)
|
||||
{
|
||||
void *receiver = test_context_socket (ZMQ_DEALER);
|
||||
|
||||
@ -95,7 +96,7 @@ void test_fair_queue_in (const char *bind_address)
|
||||
zmq_setsockopt (receiver, ZMQ_RCVTIMEO, &timeout, sizeof (int)));
|
||||
|
||||
char connect_address[MAX_SOCKET_STRING];
|
||||
test_bind (receiver, bind_address, connect_address,
|
||||
test_bind (receiver, bind_address_, connect_address,
|
||||
sizeof (connect_address));
|
||||
|
||||
const size_t services = 5;
|
||||
@ -141,25 +142,25 @@ void test_fair_queue_in (const char *bind_address)
|
||||
// SHALL create a double queue when a peer connects to it. If this peer
|
||||
// disconnects, the DEALER socket SHALL destroy its double queue and SHALL
|
||||
// discard any messages it contains.
|
||||
void test_destroy_queue_on_disconnect (const char *bind_address)
|
||||
void test_destroy_queue_on_disconnect (const char *bind_address_)
|
||||
{
|
||||
void *A = test_context_socket (ZMQ_DEALER);
|
||||
void *a = test_context_socket (ZMQ_DEALER);
|
||||
|
||||
char connect_address[MAX_SOCKET_STRING];
|
||||
test_bind (A, bind_address, connect_address, sizeof (connect_address));
|
||||
test_bind (a, bind_address_, connect_address, sizeof (connect_address));
|
||||
|
||||
void *B = test_context_socket (ZMQ_DEALER);
|
||||
void *b = test_context_socket (ZMQ_DEALER);
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (B, connect_address));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (b, connect_address));
|
||||
|
||||
// Send a message in both directions
|
||||
s_send_seq (A, "ABC", SEQ_END);
|
||||
s_send_seq (B, "DEF", SEQ_END);
|
||||
s_send_seq (a, "ABC", SEQ_END);
|
||||
s_send_seq (b, "DEF", SEQ_END);
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (B, connect_address));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (b, connect_address));
|
||||
|
||||
// Disconnect may take time and need command processing.
|
||||
zmq_pollitem_t poller[2] = {{A, 0, 0, 0}, {B, 0, 0, 0}};
|
||||
zmq_pollitem_t poller[2] = {{a, 0, 0, 0}, {b, 0, 0, 0}};
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_poll (poller, 2, 100));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_poll (poller, 2, 100));
|
||||
|
||||
@ -167,25 +168,25 @@ void test_destroy_queue_on_disconnect (const char *bind_address)
|
||||
zmq_msg_t msg;
|
||||
zmq_msg_init (&msg);
|
||||
|
||||
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_send (A, 0, 0, ZMQ_DONTWAIT));
|
||||
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_send (a, 0, 0, ZMQ_DONTWAIT));
|
||||
|
||||
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_msg_recv (&msg, A, ZMQ_DONTWAIT));
|
||||
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_msg_recv (&msg, a, ZMQ_DONTWAIT));
|
||||
|
||||
// After a reconnect of B, the messages should still be gone
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (B, connect_address));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (b, connect_address));
|
||||
|
||||
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_msg_recv (&msg, A, ZMQ_DONTWAIT));
|
||||
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_msg_recv (&msg, a, ZMQ_DONTWAIT));
|
||||
|
||||
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_msg_recv (&msg, B, ZMQ_DONTWAIT));
|
||||
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_msg_recv (&msg, b, ZMQ_DONTWAIT));
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg));
|
||||
|
||||
test_context_socket_close_zero_linger (A);
|
||||
test_context_socket_close_zero_linger (B);
|
||||
test_context_socket_close_zero_linger (a);
|
||||
test_context_socket_close_zero_linger (b);
|
||||
}
|
||||
|
||||
// SHALL block on sending, or return a suitable error, when it has no connected peers.
|
||||
void test_block_on_send_no_peers (const char *bind_address)
|
||||
void test_block_on_send_no_peers (const char *bind_address_)
|
||||
{
|
||||
void *sc = test_context_socket (ZMQ_DEALER);
|
||||
|
||||
|
@ -32,9 +32,9 @@
|
||||
const char *bind_address = 0;
|
||||
char connect_address[MAX_SOCKET_STRING];
|
||||
|
||||
void test_push_round_robin_out (void *ctx)
|
||||
void test_push_round_robin_out (void *ctx_)
|
||||
{
|
||||
void *push = zmq_socket (ctx, ZMQ_PUSH);
|
||||
void *push = zmq_socket (ctx_, ZMQ_PUSH);
|
||||
assert (push);
|
||||
|
||||
int rc = zmq_bind (push, bind_address);
|
||||
@ -46,7 +46,7 @@ void test_push_round_robin_out (void *ctx)
|
||||
const size_t services = 5;
|
||||
void *pulls[services];
|
||||
for (size_t peer = 0; peer < services; ++peer) {
|
||||
pulls[peer] = zmq_socket (ctx, ZMQ_PULL);
|
||||
pulls[peer] = zmq_socket (ctx_, ZMQ_PULL);
|
||||
assert (pulls[peer]);
|
||||
|
||||
int timeout = 250;
|
||||
@ -81,9 +81,9 @@ void test_push_round_robin_out (void *ctx)
|
||||
msleep (SETTLE_TIME);
|
||||
}
|
||||
|
||||
void test_pull_fair_queue_in (void *ctx)
|
||||
void test_pull_fair_queue_in (void *ctx_)
|
||||
{
|
||||
void *pull = zmq_socket (ctx, ZMQ_PULL);
|
||||
void *pull = zmq_socket (ctx_, ZMQ_PULL);
|
||||
assert (pull);
|
||||
|
||||
int rc = zmq_bind (pull, bind_address);
|
||||
@ -95,7 +95,7 @@ void test_pull_fair_queue_in (void *ctx)
|
||||
const unsigned char services = 5;
|
||||
void *pushs[services];
|
||||
for (unsigned char peer = 0; peer < services; ++peer) {
|
||||
pushs[peer] = zmq_socket (ctx, ZMQ_PUSH);
|
||||
pushs[peer] = zmq_socket (ctx_, ZMQ_PUSH);
|
||||
assert (pushs[peer]);
|
||||
|
||||
rc = zmq_connect (pushs[peer], connect_address);
|
||||
@ -160,9 +160,9 @@ void test_pull_fair_queue_in (void *ctx)
|
||||
msleep (SETTLE_TIME);
|
||||
}
|
||||
|
||||
void test_push_block_on_send_no_peers (void *ctx)
|
||||
void test_push_block_on_send_no_peers (void *ctx_)
|
||||
{
|
||||
void *sc = zmq_socket (ctx, ZMQ_PUSH);
|
||||
void *sc = zmq_socket (ctx_, ZMQ_PUSH);
|
||||
assert (sc);
|
||||
|
||||
int timeout = 250;
|
||||
@ -181,45 +181,45 @@ void test_push_block_on_send_no_peers (void *ctx)
|
||||
assert (rc == 0);
|
||||
}
|
||||
|
||||
void test_destroy_queue_on_disconnect (void *ctx)
|
||||
void test_destroy_queue_on_disconnect (void *ctx_)
|
||||
{
|
||||
void *A = zmq_socket (ctx, ZMQ_PUSH);
|
||||
assert (A);
|
||||
void *a = zmq_socket (ctx_, ZMQ_PUSH);
|
||||
assert (a);
|
||||
|
||||
int hwm = 1;
|
||||
int rc = zmq_setsockopt (A, ZMQ_SNDHWM, &hwm, sizeof (hwm));
|
||||
int rc = zmq_setsockopt (a, ZMQ_SNDHWM, &hwm, sizeof (hwm));
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_bind (A, bind_address);
|
||||
rc = zmq_bind (a, bind_address);
|
||||
assert (rc == 0);
|
||||
size_t len = MAX_SOCKET_STRING;
|
||||
rc = zmq_getsockopt (A, ZMQ_LAST_ENDPOINT, connect_address, &len);
|
||||
rc = zmq_getsockopt (a, ZMQ_LAST_ENDPOINT, connect_address, &len);
|
||||
assert (rc == 0);
|
||||
|
||||
void *B = zmq_socket (ctx, ZMQ_PULL);
|
||||
assert (B);
|
||||
void *b = zmq_socket (ctx_, ZMQ_PULL);
|
||||
assert (b);
|
||||
|
||||
rc = zmq_setsockopt (B, ZMQ_RCVHWM, &hwm, sizeof (hwm));
|
||||
rc = zmq_setsockopt (b, ZMQ_RCVHWM, &hwm, sizeof (hwm));
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_connect (B, connect_address);
|
||||
rc = zmq_connect (b, connect_address);
|
||||
assert (rc == 0);
|
||||
|
||||
// Send two messages, one should be stuck in A's outgoing queue, the other
|
||||
// arrives at B.
|
||||
s_send_seq (A, "ABC", SEQ_END);
|
||||
s_send_seq (A, "DEF", SEQ_END);
|
||||
s_send_seq (a, "ABC", SEQ_END);
|
||||
s_send_seq (a, "DEF", SEQ_END);
|
||||
|
||||
// Both queues should now be full, indicated by A blocking on send.
|
||||
rc = zmq_send (A, 0, 0, ZMQ_DONTWAIT);
|
||||
rc = zmq_send (a, 0, 0, ZMQ_DONTWAIT);
|
||||
assert (rc == -1);
|
||||
assert (errno == EAGAIN);
|
||||
|
||||
rc = zmq_disconnect (B, connect_address);
|
||||
rc = zmq_disconnect (b, connect_address);
|
||||
assert (rc == 0);
|
||||
|
||||
// Disconnect may take time and need command processing.
|
||||
zmq_pollitem_t poller[2] = {{A, 0, 0, 0}, {B, 0, 0, 0}};
|
||||
zmq_pollitem_t poller[2] = {{a, 0, 0, 0}, {b, 0, 0, 0}};
|
||||
rc = zmq_poll (poller, 2, 100);
|
||||
assert (rc == 0);
|
||||
rc = zmq_poll (poller, 2, 100);
|
||||
@ -230,37 +230,37 @@ void test_destroy_queue_on_disconnect (void *ctx)
|
||||
assert (rc == 0);
|
||||
|
||||
// Can't receive old data on B.
|
||||
rc = zmq_msg_recv (&msg, B, ZMQ_DONTWAIT);
|
||||
rc = zmq_msg_recv (&msg, b, ZMQ_DONTWAIT);
|
||||
assert (rc == -1);
|
||||
assert (errno == EAGAIN);
|
||||
|
||||
// Sending fails.
|
||||
rc = zmq_send (A, 0, 0, ZMQ_DONTWAIT);
|
||||
rc = zmq_send (a, 0, 0, ZMQ_DONTWAIT);
|
||||
assert (rc == -1);
|
||||
assert (errno == EAGAIN);
|
||||
|
||||
// Reconnect B
|
||||
rc = zmq_connect (B, connect_address);
|
||||
rc = zmq_connect (b, connect_address);
|
||||
assert (rc == 0);
|
||||
|
||||
// Still can't receive old data on B.
|
||||
rc = zmq_msg_recv (&msg, B, ZMQ_DONTWAIT);
|
||||
rc = zmq_msg_recv (&msg, b, ZMQ_DONTWAIT);
|
||||
assert (rc == -1);
|
||||
assert (errno == EAGAIN);
|
||||
|
||||
// two messages should be sendable before the queues are filled up.
|
||||
s_send_seq (A, "ABC", SEQ_END);
|
||||
s_send_seq (A, "DEF", SEQ_END);
|
||||
s_send_seq (a, "ABC", SEQ_END);
|
||||
s_send_seq (a, "DEF", SEQ_END);
|
||||
|
||||
rc = zmq_send (A, 0, 0, ZMQ_DONTWAIT);
|
||||
rc = zmq_send (a, 0, 0, ZMQ_DONTWAIT);
|
||||
assert (rc == -1);
|
||||
assert (errno == EAGAIN);
|
||||
|
||||
rc = zmq_msg_close (&msg);
|
||||
assert (rc == 0);
|
||||
|
||||
close_zero_linger (A);
|
||||
close_zero_linger (B);
|
||||
close_zero_linger (a);
|
||||
close_zero_linger (b);
|
||||
|
||||
// Wait for disconnects.
|
||||
msleep (SETTLE_TIME);
|
||||
|
@ -32,9 +32,9 @@
|
||||
const char *bind_address = 0;
|
||||
char connect_address[MAX_SOCKET_STRING];
|
||||
|
||||
void test_fair_queue_in (void *ctx)
|
||||
void test_fair_queue_in (void *ctx_)
|
||||
{
|
||||
void *rep = zmq_socket (ctx, ZMQ_REP);
|
||||
void *rep = zmq_socket (ctx_, ZMQ_REP);
|
||||
assert (rep);
|
||||
|
||||
int timeout = 250;
|
||||
@ -50,7 +50,7 @@ void test_fair_queue_in (void *ctx)
|
||||
const size_t services = 5;
|
||||
void *reqs[services];
|
||||
for (size_t peer = 0; peer < services; ++peer) {
|
||||
reqs[peer] = zmq_socket (ctx, ZMQ_REQ);
|
||||
reqs[peer] = zmq_socket (ctx_, ZMQ_REQ);
|
||||
assert (reqs[peer]);
|
||||
|
||||
rc = zmq_setsockopt (reqs[peer], ZMQ_RCVTIMEO, &timeout, sizeof (int));
|
||||
@ -102,9 +102,9 @@ void test_fair_queue_in (void *ctx)
|
||||
msleep (SETTLE_TIME);
|
||||
}
|
||||
|
||||
void test_envelope (void *ctx)
|
||||
void test_envelope (void *ctx_)
|
||||
{
|
||||
void *rep = zmq_socket (ctx, ZMQ_REP);
|
||||
void *rep = zmq_socket (ctx_, ZMQ_REP);
|
||||
assert (rep);
|
||||
|
||||
int rc = zmq_bind (rep, bind_address);
|
||||
@ -113,7 +113,7 @@ void test_envelope (void *ctx)
|
||||
rc = zmq_getsockopt (rep, ZMQ_LAST_ENDPOINT, connect_address, &len);
|
||||
assert (rc == 0);
|
||||
|
||||
void *dealer = zmq_socket (ctx, ZMQ_DEALER);
|
||||
void *dealer = zmq_socket (ctx_, ZMQ_DEALER);
|
||||
assert (dealer);
|
||||
|
||||
rc = zmq_connect (dealer, connect_address);
|
||||
|
@ -32,9 +32,9 @@
|
||||
const char *bind_address = 0;
|
||||
char connect_address[MAX_SOCKET_STRING];
|
||||
|
||||
void test_round_robin_out (void *ctx)
|
||||
void test_round_robin_out (void *ctx_)
|
||||
{
|
||||
void *req = zmq_socket (ctx, ZMQ_REQ);
|
||||
void *req = zmq_socket (ctx_, ZMQ_REQ);
|
||||
assert (req);
|
||||
|
||||
int rc = zmq_bind (req, bind_address);
|
||||
@ -46,7 +46,7 @@ void test_round_robin_out (void *ctx)
|
||||
const size_t services = 5;
|
||||
void *rep[services];
|
||||
for (size_t peer = 0; peer < services; peer++) {
|
||||
rep[peer] = zmq_socket (ctx, ZMQ_REP);
|
||||
rep[peer] = zmq_socket (ctx_, ZMQ_REP);
|
||||
assert (rep[peer]);
|
||||
|
||||
int timeout = 250;
|
||||
@ -77,9 +77,9 @@ void test_round_robin_out (void *ctx)
|
||||
msleep (SETTLE_TIME);
|
||||
}
|
||||
|
||||
void test_req_only_listens_to_current_peer (void *ctx)
|
||||
void test_req_only_listens_to_current_peer (void *ctx_)
|
||||
{
|
||||
void *req = zmq_socket (ctx, ZMQ_REQ);
|
||||
void *req = zmq_socket (ctx_, ZMQ_REQ);
|
||||
assert (req);
|
||||
|
||||
int rc = zmq_setsockopt (req, ZMQ_ROUTING_ID, "A", 2);
|
||||
@ -95,7 +95,7 @@ void test_req_only_listens_to_current_peer (void *ctx)
|
||||
void *router[services];
|
||||
|
||||
for (size_t i = 0; i < services; ++i) {
|
||||
router[i] = zmq_socket (ctx, ZMQ_ROUTER);
|
||||
router[i] = zmq_socket (ctx_, ZMQ_ROUTER);
|
||||
assert (router[i]);
|
||||
|
||||
int timeout = 250;
|
||||
@ -146,12 +146,12 @@ void test_req_only_listens_to_current_peer (void *ctx)
|
||||
msleep (SETTLE_TIME);
|
||||
}
|
||||
|
||||
void test_req_message_format (void *ctx)
|
||||
void test_req_message_format (void *ctx_)
|
||||
{
|
||||
void *req = zmq_socket (ctx, ZMQ_REQ);
|
||||
void *req = zmq_socket (ctx_, ZMQ_REQ);
|
||||
assert (req);
|
||||
|
||||
void *router = zmq_socket (ctx, ZMQ_ROUTER);
|
||||
void *router = zmq_socket (ctx_, ZMQ_ROUTER);
|
||||
assert (router);
|
||||
|
||||
int rc = zmq_bind (req, bind_address);
|
||||
@ -207,9 +207,9 @@ void test_req_message_format (void *ctx)
|
||||
msleep (SETTLE_TIME);
|
||||
}
|
||||
|
||||
void test_block_on_send_no_peers (void *ctx)
|
||||
void test_block_on_send_no_peers (void *ctx_)
|
||||
{
|
||||
void *sc = zmq_socket (ctx, ZMQ_REQ);
|
||||
void *sc = zmq_socket (ctx_, ZMQ_REQ);
|
||||
assert (sc);
|
||||
|
||||
int timeout = 250;
|
||||
|
@ -32,9 +32,9 @@
|
||||
const char *bind_address = 0;
|
||||
char connect_address[MAX_SOCKET_STRING];
|
||||
|
||||
void test_fair_queue_in (void *ctx)
|
||||
void test_fair_queue_in (void *ctx_)
|
||||
{
|
||||
void *receiver = zmq_socket (ctx, ZMQ_ROUTER);
|
||||
void *receiver = zmq_socket (ctx_, ZMQ_ROUTER);
|
||||
assert (receiver);
|
||||
|
||||
int timeout = 250;
|
||||
@ -50,7 +50,7 @@ void test_fair_queue_in (void *ctx)
|
||||
const unsigned char services = 5;
|
||||
void *senders[services];
|
||||
for (unsigned char peer = 0; peer < services; ++peer) {
|
||||
senders[peer] = zmq_socket (ctx, ZMQ_DEALER);
|
||||
senders[peer] = zmq_socket (ctx_, ZMQ_DEALER);
|
||||
assert (senders[peer]);
|
||||
|
||||
rc =
|
||||
@ -113,43 +113,43 @@ void test_fair_queue_in (void *ctx)
|
||||
msleep (SETTLE_TIME);
|
||||
}
|
||||
|
||||
void test_destroy_queue_on_disconnect (void *ctx)
|
||||
void test_destroy_queue_on_disconnect (void *ctx_)
|
||||
{
|
||||
void *A = zmq_socket (ctx, ZMQ_ROUTER);
|
||||
assert (A);
|
||||
void *a = zmq_socket (ctx_, ZMQ_ROUTER);
|
||||
assert (a);
|
||||
|
||||
int enabled = 1;
|
||||
int rc =
|
||||
zmq_setsockopt (A, ZMQ_ROUTER_MANDATORY, &enabled, sizeof (enabled));
|
||||
zmq_setsockopt (a, ZMQ_ROUTER_MANDATORY, &enabled, sizeof (enabled));
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_bind (A, bind_address);
|
||||
rc = zmq_bind (a, bind_address);
|
||||
assert (rc == 0);
|
||||
size_t len = MAX_SOCKET_STRING;
|
||||
rc = zmq_getsockopt (A, ZMQ_LAST_ENDPOINT, connect_address, &len);
|
||||
rc = zmq_getsockopt (a, ZMQ_LAST_ENDPOINT, connect_address, &len);
|
||||
assert (rc == 0);
|
||||
|
||||
void *B = zmq_socket (ctx, ZMQ_DEALER);
|
||||
assert (B);
|
||||
void *b = zmq_socket (ctx_, ZMQ_DEALER);
|
||||
assert (b);
|
||||
|
||||
rc = zmq_setsockopt (B, ZMQ_ROUTING_ID, "B", 2);
|
||||
rc = zmq_setsockopt (b, ZMQ_ROUTING_ID, "B", 2);
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_connect (B, connect_address);
|
||||
rc = zmq_connect (b, connect_address);
|
||||
assert (rc == 0);
|
||||
|
||||
// Wait for connection.
|
||||
msleep (SETTLE_TIME);
|
||||
|
||||
// Send a message in both directions
|
||||
s_send_seq (A, "B", "ABC", SEQ_END);
|
||||
s_send_seq (B, "DEF", SEQ_END);
|
||||
s_send_seq (a, "B", "ABC", SEQ_END);
|
||||
s_send_seq (b, "DEF", SEQ_END);
|
||||
|
||||
rc = zmq_disconnect (B, connect_address);
|
||||
rc = zmq_disconnect (b, connect_address);
|
||||
assert (rc == 0);
|
||||
|
||||
// Disconnect may take time and need command processing.
|
||||
zmq_pollitem_t poller[2] = {{A, 0, 0, 0}, {B, 0, 0, 0}};
|
||||
zmq_pollitem_t poller[2] = {{a, 0, 0, 0}, {b, 0, 0, 0}};
|
||||
rc = zmq_poll (poller, 2, 100);
|
||||
assert (rc == 0);
|
||||
rc = zmq_poll (poller, 2, 100);
|
||||
@ -159,31 +159,31 @@ void test_destroy_queue_on_disconnect (void *ctx)
|
||||
zmq_msg_t msg;
|
||||
zmq_msg_init (&msg);
|
||||
|
||||
rc = zmq_send (A, "B", 2, ZMQ_SNDMORE | ZMQ_DONTWAIT);
|
||||
rc = zmq_send (a, "B", 2, ZMQ_SNDMORE | ZMQ_DONTWAIT);
|
||||
assert (rc == -1);
|
||||
assert (errno == EHOSTUNREACH);
|
||||
|
||||
rc = zmq_msg_recv (&msg, A, ZMQ_DONTWAIT);
|
||||
rc = zmq_msg_recv (&msg, a, ZMQ_DONTWAIT);
|
||||
assert (rc == -1);
|
||||
assert (errno == EAGAIN);
|
||||
|
||||
// After a reconnect of B, the messages should still be gone
|
||||
rc = zmq_connect (B, connect_address);
|
||||
rc = zmq_connect (b, connect_address);
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_msg_recv (&msg, A, ZMQ_DONTWAIT);
|
||||
rc = zmq_msg_recv (&msg, a, ZMQ_DONTWAIT);
|
||||
assert (rc == -1);
|
||||
assert (errno == EAGAIN);
|
||||
|
||||
rc = zmq_msg_recv (&msg, B, ZMQ_DONTWAIT);
|
||||
rc = zmq_msg_recv (&msg, b, ZMQ_DONTWAIT);
|
||||
assert (rc == -1);
|
||||
assert (errno == EAGAIN);
|
||||
|
||||
rc = zmq_msg_close (&msg);
|
||||
assert (rc == 0);
|
||||
|
||||
close_zero_linger (A);
|
||||
close_zero_linger (B);
|
||||
close_zero_linger (a);
|
||||
close_zero_linger (b);
|
||||
|
||||
// Wait for disconnects.
|
||||
msleep (SETTLE_TIME);
|
||||
|
@ -77,8 +77,8 @@ int main (void)
|
||||
assert (zmq_msg_size (&msg) == MSG_SIZE);
|
||||
|
||||
// get the messages source file descriptor
|
||||
int srcFd = zmq_msg_get (&msg, ZMQ_SRCFD);
|
||||
assert (srcFd >= 0);
|
||||
int src_fd = zmq_msg_get (&msg, ZMQ_SRCFD);
|
||||
assert (src_fd >= 0);
|
||||
|
||||
rc = zmq_msg_close (&msg);
|
||||
assert (rc == 0);
|
||||
@ -90,7 +90,7 @@ int main (void)
|
||||
#else
|
||||
socklen_t addrlen = sizeof ss;
|
||||
#endif
|
||||
rc = getpeername (srcFd, (struct sockaddr *) &ss, &addrlen);
|
||||
rc = getpeername (src_fd, (struct sockaddr *) &ss, &addrlen);
|
||||
assert (rc == 0);
|
||||
|
||||
char host[NI_MAXHOST];
|
||||
@ -110,7 +110,7 @@ int main (void)
|
||||
msleep (SETTLE_TIME);
|
||||
|
||||
// getting name from closed socket will fail
|
||||
rc = getpeername (srcFd, (struct sockaddr *) &ss, &addrlen);
|
||||
rc = getpeername (src_fd, (struct sockaddr *) &ss, &addrlen);
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
assert (rc == SOCKET_ERROR);
|
||||
assert (WSAGetLastError () == WSAENOTSOCK);
|
||||
|
@ -46,19 +46,19 @@ const test_message_t dialog[] = {
|
||||
};
|
||||
const int steps = sizeof (dialog) / sizeof (dialog[0]);
|
||||
|
||||
bool has_more (void *socket)
|
||||
bool has_more (void *socket_)
|
||||
{
|
||||
int more = 0;
|
||||
size_t more_size = sizeof (more);
|
||||
int rc = zmq_getsockopt (socket, ZMQ_RCVMORE, &more, &more_size);
|
||||
int rc = zmq_getsockopt (socket_, ZMQ_RCVMORE, &more, &more_size);
|
||||
if (rc != 0)
|
||||
return false;
|
||||
return more != 0;
|
||||
}
|
||||
|
||||
bool get_routing_id (void *socket, char *data, size_t *size)
|
||||
bool get_routing_id (void *socket_, char *data_, size_t *size_)
|
||||
{
|
||||
int rc = zmq_getsockopt (socket, ZMQ_ROUTING_ID, data, size);
|
||||
int rc = zmq_getsockopt (socket_, ZMQ_ROUTING_ID, data_, size_);
|
||||
return rc == 0;
|
||||
}
|
||||
|
||||
|
@ -33,32 +33,32 @@
|
||||
// by reference, if not null, and event number by value. Returns -1
|
||||
// in case of error.
|
||||
|
||||
static int get_monitor_event (void *monitor, int *value, char **address)
|
||||
static int get_monitor_event (void *monitor_, int *value_, char **address_)
|
||||
{
|
||||
// First frame in message contains event number and value
|
||||
zmq_msg_t msg;
|
||||
zmq_msg_init (&msg);
|
||||
if (zmq_msg_recv (&msg, monitor, 0) == -1)
|
||||
if (zmq_msg_recv (&msg, monitor_, 0) == -1)
|
||||
return -1; // Interruped, presumably
|
||||
assert (zmq_msg_more (&msg));
|
||||
|
||||
uint8_t *data = (uint8_t *) zmq_msg_data (&msg);
|
||||
uint16_t event = *(uint16_t *) (data);
|
||||
if (value)
|
||||
*value = *(uint32_t *) (data + 2);
|
||||
if (value_)
|
||||
*value_ = *(uint32_t *) (data + 2);
|
||||
|
||||
// Second frame in message contains event address
|
||||
zmq_msg_init (&msg);
|
||||
if (zmq_msg_recv (&msg, monitor, 0) == -1)
|
||||
if (zmq_msg_recv (&msg, monitor_, 0) == -1)
|
||||
return -1; // Interruped, presumably
|
||||
assert (!zmq_msg_more (&msg));
|
||||
|
||||
if (address) {
|
||||
if (address_) {
|
||||
uint8_t *data = (uint8_t *) zmq_msg_data (&msg);
|
||||
size_t size = zmq_msg_size (&msg);
|
||||
*address = (char *) malloc (size + 1);
|
||||
memcpy (*address, data, size);
|
||||
*address[size] = 0;
|
||||
*address_ = (char *) malloc (size + 1);
|
||||
memcpy (*address_, data, size);
|
||||
*address_[size] = 0;
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
@ -43,12 +43,12 @@ void tearDown ()
|
||||
}
|
||||
|
||||
// Client threads loop on send/recv until told to exit
|
||||
void client_thread (void *client)
|
||||
void client_thread (void *client_)
|
||||
{
|
||||
for (int count = 0; count < 15000; count++) {
|
||||
send_string_expect_success (client, "0", 0);
|
||||
send_string_expect_success (client_, "0", 0);
|
||||
}
|
||||
send_string_expect_success (client, "1", 0);
|
||||
send_string_expect_success (client_, "1", 0);
|
||||
}
|
||||
|
||||
void test_thread_safe ()
|
||||
@ -82,12 +82,12 @@ void test_thread_safe ()
|
||||
test_context_socket_close (client);
|
||||
}
|
||||
|
||||
void test_getsockopt_thread_safe (void *const socket)
|
||||
void test_getsockopt_thread_safe (void *const socket_)
|
||||
{
|
||||
int thread_safe;
|
||||
size_t size = sizeof (int);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_getsockopt (socket, ZMQ_THREAD_SAFE, &thread_safe, &size));
|
||||
zmq_getsockopt (socket_, ZMQ_THREAD_SAFE, &thread_safe, &size));
|
||||
TEST_ASSERT_EQUAL_INT (1, thread_safe);
|
||||
}
|
||||
|
||||
|
@ -30,10 +30,10 @@
|
||||
#define __STDC_LIMIT_MACROS // to define SIZE_MAX with older compilers
|
||||
#include "testutil.hpp"
|
||||
|
||||
void handler (int timer_id, void *arg)
|
||||
void handler (int timer_id_, void *arg_)
|
||||
{
|
||||
(void) timer_id; // Stop 'unused' compiler warnings
|
||||
*((bool *) arg) = true;
|
||||
(void) timer_id_; // Stop 'unused' compiler warnings
|
||||
*((bool *) arg_) = true;
|
||||
}
|
||||
|
||||
int sleep_and_execute (void *timers_)
|
||||
|
@ -35,28 +35,28 @@ int main (void)
|
||||
int rc = zmq_bind (sb, "tcp://*:*");
|
||||
assert (rc == 0);
|
||||
|
||||
char bindEndpoint[256];
|
||||
char connectEndpoint[256];
|
||||
size_t endpoint_len = sizeof (bindEndpoint);
|
||||
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, bindEndpoint, &endpoint_len);
|
||||
char bind_endpoint[256];
|
||||
char connect_endpoint[256];
|
||||
size_t endpoint_len = sizeof (bind_endpoint);
|
||||
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, bind_endpoint, &endpoint_len);
|
||||
assert (rc == 0);
|
||||
|
||||
// Apparently Windows can't connect to 0.0.0.0. A better fix would be welcome.
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
sprintf (connectEndpoint, "tcp://127.0.0.1:%s",
|
||||
strrchr (bindEndpoint, ':') + 1);
|
||||
sprintf (connect_endpoint, "tcp://127.0.0.1:%s",
|
||||
strrchr (bind_endpoint, ':') + 1);
|
||||
#else
|
||||
strcpy (connectEndpoint, bindEndpoint);
|
||||
strcpy (connect_endpoint, bind_endpoint);
|
||||
#endif
|
||||
|
||||
rc = zmq_connect (sc, connectEndpoint);
|
||||
rc = zmq_connect (sc, connect_endpoint);
|
||||
assert (rc == 0);
|
||||
|
||||
bounce (sb, sc);
|
||||
|
||||
rc = zmq_disconnect (sc, connectEndpoint);
|
||||
rc = zmq_disconnect (sc, connect_endpoint);
|
||||
assert (rc == 0);
|
||||
rc = zmq_unbind (sb, bindEndpoint);
|
||||
rc = zmq_unbind (sb, bind_endpoint);
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_close (sc);
|
||||
@ -78,30 +78,30 @@ int main (void)
|
||||
rc = zmq_bind (sb, "tcp://*:*");
|
||||
assert (rc == 0);
|
||||
|
||||
endpoint_len = sizeof (bindEndpoint);
|
||||
memset (bindEndpoint, 0, endpoint_len);
|
||||
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, bindEndpoint, &endpoint_len);
|
||||
endpoint_len = sizeof (bind_endpoint);
|
||||
memset (bind_endpoint, 0, endpoint_len);
|
||||
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, bind_endpoint, &endpoint_len);
|
||||
assert (rc == 0);
|
||||
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
if (ipv6)
|
||||
sprintf (connectEndpoint, "tcp://[::1]:%s",
|
||||
strrchr (bindEndpoint, ':') + 1);
|
||||
sprintf (connect_endpoint, "tcp://[::1]:%s",
|
||||
strrchr (bind_endpoint, ':') + 1);
|
||||
else
|
||||
sprintf (connectEndpoint, "tcp://127.0.0.1:%s",
|
||||
strrchr (bindEndpoint, ':') + 1);
|
||||
sprintf (connect_endpoint, "tcp://127.0.0.1:%s",
|
||||
strrchr (bind_endpoint, ':') + 1);
|
||||
#else
|
||||
strcpy (connectEndpoint, bindEndpoint);
|
||||
strcpy (connect_endpoint, bind_endpoint);
|
||||
#endif
|
||||
|
||||
rc = zmq_connect (sc, connectEndpoint);
|
||||
rc = zmq_connect (sc, connect_endpoint);
|
||||
assert (rc == 0);
|
||||
|
||||
bounce (sb, sc);
|
||||
|
||||
rc = zmq_disconnect (sc, connectEndpoint);
|
||||
rc = zmq_disconnect (sc, connect_endpoint);
|
||||
assert (rc == 0);
|
||||
rc = zmq_unbind (sb, bindEndpoint);
|
||||
rc = zmq_unbind (sb, bind_endpoint);
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_close (sc);
|
||||
|
@ -33,13 +33,13 @@
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
void pre_allocate_sock (void *zmq_socket, const char *path)
|
||||
void pre_allocate_sock (void *zmq_socket_, const char *path_)
|
||||
{
|
||||
struct sockaddr_un addr;
|
||||
addr.sun_family = AF_UNIX;
|
||||
strcpy (addr.sun_path, path);
|
||||
strcpy (addr.sun_path, path_);
|
||||
|
||||
unlink (path);
|
||||
unlink (path_);
|
||||
|
||||
int s_pre = socket (AF_UNIX, SOCK_STREAM, 0);
|
||||
assert (s_pre != -1);
|
||||
@ -51,7 +51,7 @@ void pre_allocate_sock (void *zmq_socket, const char *path)
|
||||
rc = listen (s_pre, SOMAXCONN);
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_setsockopt (zmq_socket, ZMQ_USE_FD, &s_pre, sizeof (s_pre));
|
||||
rc = zmq_setsockopt (zmq_socket_, ZMQ_USE_FD, &s_pre, sizeof (s_pre));
|
||||
assert (rc == 0);
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include <netdb.h>
|
||||
|
||||
uint16_t
|
||||
pre_allocate_sock (void *zmq_socket, const char *address, const char *port)
|
||||
pre_allocate_sock (void *zmq_socket_, const char *address_, const char *port_)
|
||||
{
|
||||
struct addrinfo *addr, hint;
|
||||
hint.ai_flags = 0;
|
||||
@ -45,7 +45,7 @@ pre_allocate_sock (void *zmq_socket, const char *address, const char *port)
|
||||
hint.ai_addr = NULL;
|
||||
hint.ai_next = NULL;
|
||||
|
||||
int rc = getaddrinfo (address, port, &hint, &addr);
|
||||
int rc = getaddrinfo (address_, port_, &hint, &addr);
|
||||
assert (rc == 0);
|
||||
|
||||
int s_pre = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
@ -61,7 +61,7 @@ pre_allocate_sock (void *zmq_socket, const char *address, const char *port)
|
||||
rc = listen (s_pre, SOMAXCONN);
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_setsockopt (zmq_socket, ZMQ_USE_FD, &s_pre, sizeof (s_pre));
|
||||
rc = zmq_setsockopt (zmq_socket_, ZMQ_USE_FD, &s_pre, sizeof (s_pre));
|
||||
assert (rc == 0);
|
||||
|
||||
struct sockaddr_in sin;
|
||||
|
@ -111,9 +111,9 @@ enum
|
||||
#endif
|
||||
#else
|
||||
typedef size_t socket_size_t;
|
||||
const void *as_setsockopt_opt_t (const void *opt)
|
||||
const void *as_setsockopt_opt_t (const void *opt_)
|
||||
{
|
||||
return opt;
|
||||
return opt_;
|
||||
}
|
||||
typedef int fd_t;
|
||||
enum
|
||||
@ -126,94 +126,94 @@ enum
|
||||
|
||||
// Bounce a message from client to server and back
|
||||
// For REQ/REP or DEALER/DEALER pairs only
|
||||
void bounce (void *server, void *client)
|
||||
void bounce (void *server_, void *client_)
|
||||
{
|
||||
const char *content = "12345678ABCDEFGH12345678abcdefgh";
|
||||
|
||||
// Send message from client to server
|
||||
int rc = zmq_send (client, content, 32, ZMQ_SNDMORE);
|
||||
int rc = zmq_send (client_, content, 32, ZMQ_SNDMORE);
|
||||
assert (rc == 32);
|
||||
rc = zmq_send (client, content, 32, 0);
|
||||
rc = zmq_send (client_, content, 32, 0);
|
||||
assert (rc == 32);
|
||||
|
||||
// Receive message at server side
|
||||
char buffer[32];
|
||||
rc = zmq_recv (server, buffer, 32, 0);
|
||||
rc = zmq_recv (server_, buffer, 32, 0);
|
||||
assert (rc == 32);
|
||||
// Check that message is still the same
|
||||
assert (memcmp (buffer, content, 32) == 0);
|
||||
int rcvmore;
|
||||
size_t sz = sizeof (rcvmore);
|
||||
rc = zmq_getsockopt (server, ZMQ_RCVMORE, &rcvmore, &sz);
|
||||
rc = zmq_getsockopt (server_, ZMQ_RCVMORE, &rcvmore, &sz);
|
||||
assert (rc == 0);
|
||||
assert (rcvmore);
|
||||
rc = zmq_recv (server, buffer, 32, 0);
|
||||
rc = zmq_recv (server_, buffer, 32, 0);
|
||||
assert (rc == 32);
|
||||
// Check that message is still the same
|
||||
assert (memcmp (buffer, content, 32) == 0);
|
||||
rc = zmq_getsockopt (server, ZMQ_RCVMORE, &rcvmore, &sz);
|
||||
rc = zmq_getsockopt (server_, ZMQ_RCVMORE, &rcvmore, &sz);
|
||||
assert (rc == 0);
|
||||
assert (!rcvmore);
|
||||
|
||||
// Send two parts back to client
|
||||
rc = zmq_send (server, buffer, 32, ZMQ_SNDMORE);
|
||||
rc = zmq_send (server_, buffer, 32, ZMQ_SNDMORE);
|
||||
assert (rc == 32);
|
||||
rc = zmq_send (server, buffer, 32, 0);
|
||||
rc = zmq_send (server_, buffer, 32, 0);
|
||||
assert (rc == 32);
|
||||
|
||||
// Receive the two parts at the client side
|
||||
rc = zmq_recv (client, buffer, 32, 0);
|
||||
rc = zmq_recv (client_, buffer, 32, 0);
|
||||
assert (rc == 32);
|
||||
// Check that message is still the same
|
||||
assert (memcmp (buffer, content, 32) == 0);
|
||||
rc = zmq_getsockopt (client, ZMQ_RCVMORE, &rcvmore, &sz);
|
||||
rc = zmq_getsockopt (client_, ZMQ_RCVMORE, &rcvmore, &sz);
|
||||
assert (rc == 0);
|
||||
assert (rcvmore);
|
||||
rc = zmq_recv (client, buffer, 32, 0);
|
||||
rc = zmq_recv (client_, buffer, 32, 0);
|
||||
assert (rc == 32);
|
||||
// Check that message is still the same
|
||||
assert (memcmp (buffer, content, 32) == 0);
|
||||
rc = zmq_getsockopt (client, ZMQ_RCVMORE, &rcvmore, &sz);
|
||||
rc = zmq_getsockopt (client_, ZMQ_RCVMORE, &rcvmore, &sz);
|
||||
assert (rc == 0);
|
||||
assert (!rcvmore);
|
||||
}
|
||||
|
||||
// Same as bounce, but expect messages to never arrive
|
||||
// for security or subscriber reasons.
|
||||
void expect_bounce_fail (void *server, void *client)
|
||||
void expect_bounce_fail (void *server_, void *client_)
|
||||
{
|
||||
const char *content = "12345678ABCDEFGH12345678abcdefgh";
|
||||
char buffer[32];
|
||||
int timeout = 250;
|
||||
|
||||
// Send message from client to server
|
||||
int rc = zmq_setsockopt (client, ZMQ_SNDTIMEO, &timeout, sizeof (int));
|
||||
int rc = zmq_setsockopt (client_, ZMQ_SNDTIMEO, &timeout, sizeof (int));
|
||||
assert (rc == 0);
|
||||
rc = zmq_send (client, content, 32, ZMQ_SNDMORE);
|
||||
rc = zmq_send (client_, content, 32, ZMQ_SNDMORE);
|
||||
assert ((rc == 32) || ((rc == -1) && (errno == EAGAIN)));
|
||||
rc = zmq_send (client, content, 32, 0);
|
||||
rc = zmq_send (client_, content, 32, 0);
|
||||
assert ((rc == 32) || ((rc == -1) && (errno == EAGAIN)));
|
||||
|
||||
// Receive message at server side (should not succeed)
|
||||
rc = zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof (int));
|
||||
rc = zmq_setsockopt (server_, ZMQ_RCVTIMEO, &timeout, sizeof (int));
|
||||
assert (rc == 0);
|
||||
rc = zmq_recv (server, buffer, 32, 0);
|
||||
rc = zmq_recv (server_, buffer, 32, 0);
|
||||
assert (rc == -1);
|
||||
assert (zmq_errno () == EAGAIN);
|
||||
|
||||
// Send message from server to client to test other direction
|
||||
// If connection failed, send may block, without a timeout
|
||||
rc = zmq_setsockopt (server, ZMQ_SNDTIMEO, &timeout, sizeof (int));
|
||||
rc = zmq_setsockopt (server_, ZMQ_SNDTIMEO, &timeout, sizeof (int));
|
||||
assert (rc == 0);
|
||||
rc = zmq_send (server, content, 32, ZMQ_SNDMORE);
|
||||
rc = zmq_send (server_, content, 32, ZMQ_SNDMORE);
|
||||
assert (rc == 32 || (rc == -1 && zmq_errno () == EAGAIN));
|
||||
rc = zmq_send (server, content, 32, 0);
|
||||
rc = zmq_send (server_, content, 32, 0);
|
||||
assert (rc == 32 || (rc == -1 && zmq_errno () == EAGAIN));
|
||||
|
||||
// Receive message at client side (should not succeed)
|
||||
rc = zmq_setsockopt (client, ZMQ_RCVTIMEO, &timeout, sizeof (int));
|
||||
rc = zmq_setsockopt (client_, ZMQ_RCVTIMEO, &timeout, sizeof (int));
|
||||
assert (rc == 0);
|
||||
rc = zmq_recv (client, buffer, 32, 0);
|
||||
rc = zmq_recv (client_, buffer, 32, 0);
|
||||
assert (rc == -1);
|
||||
assert (zmq_errno () == EAGAIN);
|
||||
}
|
||||
@ -221,10 +221,10 @@ void expect_bounce_fail (void *server, void *client)
|
||||
// Receive 0MQ string from socket and convert into C string
|
||||
// Caller must free returned string. Returns NULL if the context
|
||||
// is being terminated.
|
||||
char *s_recv (void *socket)
|
||||
char *s_recv (void *socket_)
|
||||
{
|
||||
char buffer[256];
|
||||
int size = zmq_recv (socket, buffer, 255, 0);
|
||||
int size = zmq_recv (socket_, buffer, 255, 0);
|
||||
if (size == -1)
|
||||
return NULL;
|
||||
if (size > 255)
|
||||
@ -234,16 +234,16 @@ char *s_recv (void *socket)
|
||||
}
|
||||
|
||||
// Convert C string to 0MQ string and send to socket
|
||||
int s_send (void *socket, const char *string)
|
||||
int s_send (void *socket_, const char *string_)
|
||||
{
|
||||
int size = zmq_send (socket, string, strlen (string), 0);
|
||||
int size = zmq_send (socket_, string_, strlen (string_), 0);
|
||||
return size;
|
||||
}
|
||||
|
||||
// Sends string as 0MQ string, as multipart non-terminal
|
||||
int s_sendmore (void *socket, const char *string)
|
||||
int s_sendmore (void *socket_, const char *string_)
|
||||
{
|
||||
int size = zmq_send (socket, string, strlen (string), ZMQ_SNDMORE);
|
||||
int size = zmq_send (socket_, string_, strlen (string_), ZMQ_SNDMORE);
|
||||
return size;
|
||||
}
|
||||
|
||||
@ -256,10 +256,10 @@ const char *SEQ_END = (const char *) 1;
|
||||
// The list must be terminated by SEQ_END.
|
||||
// Example: s_send_seq (req, "ABC", 0, "DEF", SEQ_END);
|
||||
|
||||
void s_send_seq (void *socket, ...)
|
||||
void s_send_seq (void *socket_, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, socket);
|
||||
va_start (ap, socket_);
|
||||
const char *data = va_arg (ap, const char *);
|
||||
while (true) {
|
||||
const char *prev = data;
|
||||
@ -267,11 +267,11 @@ void s_send_seq (void *socket, ...)
|
||||
bool end = data == SEQ_END;
|
||||
|
||||
if (!prev) {
|
||||
int rc = zmq_send (socket, 0, 0, end ? 0 : ZMQ_SNDMORE);
|
||||
int rc = zmq_send (socket_, 0, 0, end ? 0 : ZMQ_SNDMORE);
|
||||
assert (rc != -1);
|
||||
} else {
|
||||
int rc =
|
||||
zmq_send (socket, prev, strlen (prev) + 1, end ? 0 : ZMQ_SNDMORE);
|
||||
int rc = zmq_send (socket_, prev, strlen (prev) + 1,
|
||||
end ? 0 : ZMQ_SNDMORE);
|
||||
assert (rc != -1);
|
||||
}
|
||||
if (end)
|
||||
@ -285,7 +285,7 @@ void s_send_seq (void *socket, ...)
|
||||
// The list must be terminated by SEQ_END.
|
||||
// Example: s_recv_seq (rep, "ABC", 0, "DEF", SEQ_END);
|
||||
|
||||
void s_recv_seq (void *socket, ...)
|
||||
void s_recv_seq (void *socket_, ...)
|
||||
{
|
||||
zmq_msg_t msg;
|
||||
zmq_msg_init (&msg);
|
||||
@ -294,11 +294,11 @@ void s_recv_seq (void *socket, ...)
|
||||
size_t more_size = sizeof (more);
|
||||
|
||||
va_list ap;
|
||||
va_start (ap, socket);
|
||||
va_start (ap, socket_);
|
||||
const char *data = va_arg (ap, const char *);
|
||||
|
||||
while (true) {
|
||||
int rc = zmq_msg_recv (&msg, socket, 0);
|
||||
int rc = zmq_msg_recv (&msg, socket_, 0);
|
||||
assert (rc != -1);
|
||||
|
||||
if (!data)
|
||||
@ -309,7 +309,7 @@ void s_recv_seq (void *socket, ...)
|
||||
data = va_arg (ap, const char *);
|
||||
bool end = data == SEQ_END;
|
||||
|
||||
rc = zmq_getsockopt (socket, ZMQ_RCVMORE, &more, &more_size);
|
||||
rc = zmq_getsockopt (socket_, ZMQ_RCVMORE, &more, &more_size);
|
||||
assert (rc == 0);
|
||||
|
||||
assert (!more == end);
|
||||
@ -323,12 +323,12 @@ void s_recv_seq (void *socket, ...)
|
||||
|
||||
|
||||
// Sets a zero linger period on a socket and closes it.
|
||||
void close_zero_linger (void *socket)
|
||||
void close_zero_linger (void *socket_)
|
||||
{
|
||||
int linger = 0;
|
||||
int rc = zmq_setsockopt (socket, ZMQ_LINGER, &linger, sizeof (linger));
|
||||
int rc = zmq_setsockopt (socket_, ZMQ_LINGER, &linger, sizeof (linger));
|
||||
assert (rc == 0 || errno == ETERM);
|
||||
rc = zmq_close (socket);
|
||||
rc = zmq_close (socket_);
|
||||
assert (rc == 0);
|
||||
}
|
||||
|
||||
@ -362,12 +362,12 @@ void setup_test_environment (void)
|
||||
// http://www.cplusplus.com/forum/unices/60161/
|
||||
// http://en.cppreference.com/w/cpp/thread/sleep_for
|
||||
|
||||
void msleep (int milliseconds)
|
||||
void msleep (int milliseconds_)
|
||||
{
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
Sleep (milliseconds);
|
||||
Sleep (milliseconds_);
|
||||
#else
|
||||
usleep (static_cast<useconds_t> (milliseconds) * 1000);
|
||||
usleep (static_cast<useconds_t> (milliseconds_) * 1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -39,24 +39,24 @@ typedef void(socket_config_fn) (void *, void *);
|
||||
const char *test_zap_domain = "ZAPTEST";
|
||||
|
||||
// NULL specific functions
|
||||
void socket_config_null_client (void *server, void *server_secret)
|
||||
void socket_config_null_client (void *server_, void *server_secret_)
|
||||
{
|
||||
LIBZMQ_UNUSED (server);
|
||||
LIBZMQ_UNUSED (server_secret);
|
||||
LIBZMQ_UNUSED (server_);
|
||||
LIBZMQ_UNUSED (server_secret_);
|
||||
}
|
||||
|
||||
void socket_config_null_server (void *server, void *server_secret)
|
||||
void socket_config_null_server (void *server_, void *server_secret_)
|
||||
{
|
||||
int rc = zmq_setsockopt (server, ZMQ_ZAP_DOMAIN, test_zap_domain,
|
||||
int rc = zmq_setsockopt (server_, ZMQ_ZAP_DOMAIN, test_zap_domain,
|
||||
strlen (test_zap_domain));
|
||||
assert (rc == 0);
|
||||
#ifdef ZMQ_ZAP_ENFORCE_DOMAIN
|
||||
int required = server_secret ? *(int *) server_secret : 0;
|
||||
int required = server_secret_ ? *(int *) server_secret_ : 0;
|
||||
rc =
|
||||
zmq_setsockopt (server, ZMQ_ZAP_ENFORCE_DOMAIN, &required, sizeof (int));
|
||||
zmq_setsockopt (server_, ZMQ_ZAP_ENFORCE_DOMAIN, &required, sizeof (int));
|
||||
assert (rc == 0);
|
||||
#else
|
||||
LIBZMQ_UNUSED (server_secret);
|
||||
LIBZMQ_UNUSED (server_secret_);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -64,28 +64,28 @@ void socket_config_null_server (void *server, void *server_secret)
|
||||
const char *test_plain_username = "testuser";
|
||||
const char *test_plain_password = "testpass";
|
||||
|
||||
void socket_config_plain_client (void *server, void *server_secret)
|
||||
void socket_config_plain_client (void *server_, void *server_secret_)
|
||||
{
|
||||
LIBZMQ_UNUSED (server_secret);
|
||||
LIBZMQ_UNUSED (server_secret_);
|
||||
|
||||
int rc =
|
||||
zmq_setsockopt (server, ZMQ_PLAIN_PASSWORD, test_plain_password, 8);
|
||||
zmq_setsockopt (server_, ZMQ_PLAIN_PASSWORD, test_plain_password, 8);
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_setsockopt (server, ZMQ_PLAIN_USERNAME, test_plain_username, 8);
|
||||
rc = zmq_setsockopt (server_, ZMQ_PLAIN_USERNAME, test_plain_username, 8);
|
||||
assert (rc == 0);
|
||||
}
|
||||
|
||||
void socket_config_plain_server (void *server, void *server_secret)
|
||||
void socket_config_plain_server (void *server_, void *server_secret_)
|
||||
{
|
||||
LIBZMQ_UNUSED (server_secret);
|
||||
LIBZMQ_UNUSED (server_secret_);
|
||||
|
||||
int as_server = 1;
|
||||
int rc =
|
||||
zmq_setsockopt (server, ZMQ_PLAIN_SERVER, &as_server, sizeof (int));
|
||||
zmq_setsockopt (server_, ZMQ_PLAIN_SERVER, &as_server, sizeof (int));
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_setsockopt (server, ZMQ_ZAP_DOMAIN, test_zap_domain,
|
||||
rc = zmq_setsockopt (server_, ZMQ_ZAP_DOMAIN, test_zap_domain,
|
||||
strlen (test_zap_domain));
|
||||
assert (rc == 0);
|
||||
}
|
||||
@ -107,24 +107,24 @@ void setup_testutil_security_curve ()
|
||||
assert (rc == 0);
|
||||
}
|
||||
|
||||
void socket_config_curve_server (void *server, void *server_secret)
|
||||
void socket_config_curve_server (void *server_, void *server_secret_)
|
||||
{
|
||||
int as_server = 1;
|
||||
int rc =
|
||||
zmq_setsockopt (server, ZMQ_CURVE_SERVER, &as_server, sizeof (int));
|
||||
zmq_setsockopt (server_, ZMQ_CURVE_SERVER, &as_server, sizeof (int));
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_setsockopt (server, ZMQ_CURVE_SECRETKEY, server_secret, 41);
|
||||
rc = zmq_setsockopt (server_, ZMQ_CURVE_SECRETKEY, server_secret_, 41);
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_setsockopt (server, ZMQ_ZAP_DOMAIN, test_zap_domain,
|
||||
rc = zmq_setsockopt (server_, ZMQ_ZAP_DOMAIN, test_zap_domain,
|
||||
strlen (test_zap_domain));
|
||||
assert (rc == 0);
|
||||
|
||||
#ifdef ZMQ_ZAP_ENFORCE_DOMAIN
|
||||
int required = 1;
|
||||
rc =
|
||||
zmq_setsockopt (server, ZMQ_ZAP_ENFORCE_DOMAIN, &required, sizeof (int));
|
||||
zmq_setsockopt (server_, ZMQ_ZAP_ENFORCE_DOMAIN, &required, sizeof (int));
|
||||
assert (rc == 0);
|
||||
#endif
|
||||
}
|
||||
@ -136,18 +136,18 @@ struct curve_client_data_t
|
||||
const char *client_secret;
|
||||
};
|
||||
|
||||
void socket_config_curve_client (void *client, void *data)
|
||||
void socket_config_curve_client (void *client_, void *data_)
|
||||
{
|
||||
curve_client_data_t *curve_client_data =
|
||||
static_cast<curve_client_data_t *> (data);
|
||||
static_cast<curve_client_data_t *> (data_);
|
||||
|
||||
int rc = zmq_setsockopt (client, ZMQ_CURVE_SERVERKEY,
|
||||
int rc = zmq_setsockopt (client_, ZMQ_CURVE_SERVERKEY,
|
||||
curve_client_data->server_public, 41);
|
||||
assert (rc == 0);
|
||||
rc = zmq_setsockopt (client, ZMQ_CURVE_PUBLICKEY,
|
||||
rc = zmq_setsockopt (client_, ZMQ_CURVE_PUBLICKEY,
|
||||
curve_client_data->client_public, 41);
|
||||
assert (rc == 0);
|
||||
rc = zmq_setsockopt (client, ZMQ_CURVE_SECRETKEY,
|
||||
rc = zmq_setsockopt (client_, ZMQ_CURVE_SECRETKEY,
|
||||
curve_client_data->client_secret, 41);
|
||||
assert (rc == 0);
|
||||
}
|
||||
@ -174,16 +174,16 @@ enum zap_protocol_t
|
||||
|
||||
void *zap_requests_handled;
|
||||
|
||||
void zap_handler_generic (void *ctx,
|
||||
zap_protocol_t zap_protocol,
|
||||
const char *expected_routing_id = "IDENT")
|
||||
void zap_handler_generic (void *ctx_,
|
||||
zap_protocol_t zap_protocol_,
|
||||
const char *expected_routing_id_ = "IDENT")
|
||||
{
|
||||
void *control = zmq_socket (ctx, ZMQ_REQ);
|
||||
void *control = zmq_socket (ctx_, ZMQ_REQ);
|
||||
assert (control);
|
||||
int rc = zmq_connect (control, "inproc://handler-control");
|
||||
assert (rc == 0);
|
||||
|
||||
void *handler = zmq_socket (ctx, ZMQ_REP);
|
||||
void *handler = zmq_socket (ctx_, ZMQ_REP);
|
||||
assert (handler);
|
||||
rc = zmq_bind (handler, "inproc://zeromq.zap.01");
|
||||
assert (rc == 0);
|
||||
@ -198,7 +198,7 @@ void zap_handler_generic (void *ctx,
|
||||
};
|
||||
|
||||
// if ordered not to receive the request, ignore the second poll item
|
||||
const int numitems = (zap_protocol == zap_do_not_recv) ? 1 : 2;
|
||||
const int numitems = (zap_protocol_ == zap_do_not_recv) ? 1 : 2;
|
||||
|
||||
// Process ZAP requests forever
|
||||
while (zmq_poll (items, numitems, -1) >= 0) {
|
||||
@ -215,7 +215,7 @@ void zap_handler_generic (void *ctx,
|
||||
char *version = s_recv (handler);
|
||||
if (!version)
|
||||
break; // Terminating - peer's socket closed
|
||||
if (zap_protocol == zap_disconnect) {
|
||||
if (zap_protocol_ == zap_disconnect) {
|
||||
free (version);
|
||||
break;
|
||||
}
|
||||
@ -258,18 +258,18 @@ void zap_handler_generic (void *ctx,
|
||||
}
|
||||
|
||||
assert (streq (version, "1.0"));
|
||||
assert (streq (routing_id, expected_routing_id));
|
||||
assert (streq (routing_id, expected_routing_id_));
|
||||
|
||||
s_sendmore (handler, zap_protocol == zap_wrong_version
|
||||
s_sendmore (handler, zap_protocol_ == zap_wrong_version
|
||||
? "invalid_version"
|
||||
: version);
|
||||
s_sendmore (handler, zap_protocol == zap_wrong_request_id
|
||||
s_sendmore (handler, zap_protocol_ == zap_wrong_request_id
|
||||
? "invalid_request_id"
|
||||
: sequence);
|
||||
|
||||
if (authentication_succeeded) {
|
||||
const char *status_code;
|
||||
switch (zap_protocol) {
|
||||
switch (zap_protocol_) {
|
||||
case zap_status_internal_error:
|
||||
status_code = "500";
|
||||
break;
|
||||
@ -285,16 +285,16 @@ void zap_handler_generic (void *ctx,
|
||||
s_sendmore (handler, status_code);
|
||||
s_sendmore (handler, "OK");
|
||||
s_sendmore (handler, "anonymous");
|
||||
if (zap_protocol == zap_too_many_parts) {
|
||||
if (zap_protocol_ == zap_too_many_parts) {
|
||||
s_sendmore (handler, "");
|
||||
}
|
||||
if (zap_protocol != zap_do_not_send)
|
||||
if (zap_protocol_ != zap_do_not_send)
|
||||
s_send (handler, "");
|
||||
} else {
|
||||
s_sendmore (handler, "400");
|
||||
s_sendmore (handler, "Invalid client public key");
|
||||
s_sendmore (handler, "");
|
||||
if (zap_protocol != zap_do_not_send)
|
||||
if (zap_protocol_ != zap_do_not_send)
|
||||
s_send (handler, "");
|
||||
}
|
||||
free (version);
|
||||
@ -310,16 +310,16 @@ void zap_handler_generic (void *ctx,
|
||||
assert (rc == 0);
|
||||
close_zero_linger (handler);
|
||||
|
||||
if (zap_protocol != zap_disconnect) {
|
||||
if (zap_protocol_ != zap_disconnect) {
|
||||
rc = s_send (control, "STOPPED");
|
||||
assert (rc == 7);
|
||||
}
|
||||
close_zero_linger (control);
|
||||
}
|
||||
|
||||
void zap_handler (void *ctx)
|
||||
void zap_handler (void *ctx_)
|
||||
{
|
||||
zap_handler_generic (ctx, zap_ok);
|
||||
zap_handler_generic (ctx_, zap_ok);
|
||||
}
|
||||
|
||||
// Monitor event utilities
|
||||
@ -328,15 +328,15 @@ void zap_handler (void *ctx)
|
||||
// by reference, if not null, and event number by value. Returns -1
|
||||
// in case of error.
|
||||
|
||||
static int get_monitor_event_internal (void *monitor,
|
||||
int *value,
|
||||
char **address,
|
||||
int recv_flag)
|
||||
static int get_monitor_event_internal (void *monitor_,
|
||||
int *value_,
|
||||
char **address_,
|
||||
int recv_flag_)
|
||||
{
|
||||
// First frame in message contains event number and value
|
||||
zmq_msg_t msg;
|
||||
zmq_msg_init (&msg);
|
||||
if (zmq_msg_recv (&msg, monitor, recv_flag) == -1) {
|
||||
if (zmq_msg_recv (&msg, monitor_, recv_flag_) == -1) {
|
||||
assert (errno == EAGAIN);
|
||||
return -1; // timed out or no message available
|
||||
}
|
||||
@ -344,81 +344,82 @@ static int get_monitor_event_internal (void *monitor,
|
||||
|
||||
uint8_t *data = (uint8_t *) zmq_msg_data (&msg);
|
||||
uint16_t event = *(uint16_t *) (data);
|
||||
if (value)
|
||||
*value = *(uint32_t *) (data + 2);
|
||||
if (value_)
|
||||
*value_ = *(uint32_t *) (data + 2);
|
||||
|
||||
// Second frame in message contains event address
|
||||
zmq_msg_init (&msg);
|
||||
int res = zmq_msg_recv (&msg, monitor, recv_flag) == -1;
|
||||
int res = zmq_msg_recv (&msg, monitor_, recv_flag_) == -1;
|
||||
assert (res != -1);
|
||||
assert (!zmq_msg_more (&msg));
|
||||
|
||||
if (address) {
|
||||
if (address_) {
|
||||
uint8_t *data = (uint8_t *) zmq_msg_data (&msg);
|
||||
size_t size = zmq_msg_size (&msg);
|
||||
*address = (char *) malloc (size + 1);
|
||||
memcpy (*address, data, size);
|
||||
*address[size] = 0;
|
||||
*address_ = (char *) malloc (size + 1);
|
||||
memcpy (*address_, data, size);
|
||||
*address_[size] = 0;
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
int get_monitor_event_with_timeout (void *monitor,
|
||||
int *value,
|
||||
char **address,
|
||||
int timeout)
|
||||
int get_monitor_event_with_timeout (void *monitor_,
|
||||
int *value_,
|
||||
char **address_,
|
||||
int timeout_)
|
||||
{
|
||||
int res;
|
||||
if (timeout == -1) {
|
||||
if (timeout_ == -1) {
|
||||
// process infinite timeout in small steps to allow the user
|
||||
// to see some information on the console
|
||||
|
||||
int timeout_step = 250;
|
||||
int wait_time = 0;
|
||||
zmq_setsockopt (monitor, ZMQ_RCVTIMEO, &timeout_step,
|
||||
zmq_setsockopt (monitor_, ZMQ_RCVTIMEO, &timeout_step,
|
||||
sizeof (timeout_step));
|
||||
while ((res = get_monitor_event_internal (monitor, value, address, 0))
|
||||
== -1) {
|
||||
while (
|
||||
(res = get_monitor_event_internal (monitor_, value_, address_, 0))
|
||||
== -1) {
|
||||
wait_time += timeout_step;
|
||||
fprintf (stderr, "Still waiting for monitor event after %i ms\n",
|
||||
wait_time);
|
||||
}
|
||||
} else {
|
||||
zmq_setsockopt (monitor, ZMQ_RCVTIMEO, &timeout, sizeof (timeout));
|
||||
res = get_monitor_event_internal (monitor, value, address, 0);
|
||||
zmq_setsockopt (monitor_, ZMQ_RCVTIMEO, &timeout_, sizeof (timeout_));
|
||||
res = get_monitor_event_internal (monitor_, value_, address_, 0);
|
||||
}
|
||||
int timeout_infinite = -1;
|
||||
zmq_setsockopt (monitor, ZMQ_RCVTIMEO, &timeout_infinite,
|
||||
zmq_setsockopt (monitor_, ZMQ_RCVTIMEO, &timeout_infinite,
|
||||
sizeof (timeout_infinite));
|
||||
return res;
|
||||
}
|
||||
|
||||
int get_monitor_event (void *monitor, int *value, char **address)
|
||||
int get_monitor_event (void *monitor_, int *value_, char **address_)
|
||||
{
|
||||
return get_monitor_event_with_timeout (monitor, value, address, -1);
|
||||
return get_monitor_event_with_timeout (monitor_, value_, address_, -1);
|
||||
}
|
||||
|
||||
void expect_monitor_event (void *monitor, int expected_event)
|
||||
void expect_monitor_event (void *monitor_, int expected_event_)
|
||||
{
|
||||
int event = get_monitor_event (monitor, NULL, NULL);
|
||||
if (event != expected_event) {
|
||||
int event = get_monitor_event (monitor_, NULL, NULL);
|
||||
if (event != expected_event_) {
|
||||
fprintf (stderr, "Expected monitor event %x but received %x\n",
|
||||
expected_event, event);
|
||||
assert (event == expected_event);
|
||||
expected_event_, event);
|
||||
assert (event == expected_event_);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
|
||||
void print_unexpected_event (int event,
|
||||
int err,
|
||||
int expected_event,
|
||||
int expected_err)
|
||||
void print_unexpected_event (int event_,
|
||||
int err_,
|
||||
int expected_event_,
|
||||
int expected_err_)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"Unexpected event: 0x%x, value = %i/0x%x (expected: 0x%x, value "
|
||||
"= %i/0x%x)\n",
|
||||
event, err, err, expected_event, expected_err, expected_err);
|
||||
event_, err_, err_, expected_event_, expected_err_, expected_err_);
|
||||
}
|
||||
|
||||
// expects that one or more occurrences of the expected event are received
|
||||
@ -428,10 +429,10 @@ void print_unexpected_event (int event,
|
||||
// or ECONNABORTED occurs; in this case, 0 is returned
|
||||
// this should be investigated further, see
|
||||
// https://github.com/zeromq/libzmq/issues/2644
|
||||
int expect_monitor_event_multiple (void *server_mon,
|
||||
int expected_event,
|
||||
int expected_err = -1,
|
||||
bool optional = false)
|
||||
int expect_monitor_event_multiple (void *server_mon_,
|
||||
int expected_event_,
|
||||
int expected_err_ = -1,
|
||||
bool optional_ = false)
|
||||
{
|
||||
int count_of_expected_events = 0;
|
||||
int client_closed_connection = 0;
|
||||
@ -440,18 +441,18 @@ int expect_monitor_event_multiple (void *server_mon,
|
||||
|
||||
int event;
|
||||
int err;
|
||||
while (
|
||||
(event = get_monitor_event_with_timeout (server_mon, &err, NULL, timeout))
|
||||
!= -1
|
||||
|| !count_of_expected_events) {
|
||||
while ((event =
|
||||
get_monitor_event_with_timeout (server_mon_, &err, NULL, timeout))
|
||||
!= -1
|
||||
|| !count_of_expected_events) {
|
||||
if (event == -1) {
|
||||
if (optional)
|
||||
if (optional_)
|
||||
break;
|
||||
wait_time += timeout;
|
||||
fprintf (stderr,
|
||||
"Still waiting for first event after %ims (expected event "
|
||||
"%x (value %i/0x%x))\n",
|
||||
wait_time, expected_event, expected_err, expected_err);
|
||||
wait_time, expected_event_, expected_err_, expected_err_);
|
||||
continue;
|
||||
}
|
||||
// ignore errors with EPIPE/ECONNRESET/ECONNABORTED, which can happen
|
||||
@ -459,7 +460,7 @@ int expect_monitor_event_multiple (void *server_mon,
|
||||
// to the peer and then tries to read the socket before the peer reads
|
||||
// ECONNABORTED happens when a client aborts a connection via RST/timeout
|
||||
if (event == ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL
|
||||
&& ((err == EPIPE && expected_err != EPIPE) || err == ECONNRESET
|
||||
&& ((err == EPIPE && expected_err_ != EPIPE) || err == ECONNRESET
|
||||
|| err == ECONNABORTED)) {
|
||||
fprintf (stderr,
|
||||
"Ignored event (skipping any further events): %x (err = "
|
||||
@ -468,14 +469,14 @@ int expect_monitor_event_multiple (void *server_mon,
|
||||
client_closed_connection = 1;
|
||||
break;
|
||||
}
|
||||
if (event != expected_event
|
||||
|| (-1 != expected_err && err != expected_err)) {
|
||||
print_unexpected_event (event, err, expected_event, expected_err);
|
||||
if (event != expected_event_
|
||||
|| (-1 != expected_err_ && err != expected_err_)) {
|
||||
print_unexpected_event (event, err, expected_event_, expected_err_);
|
||||
assert (false);
|
||||
}
|
||||
++count_of_expected_events;
|
||||
}
|
||||
assert (optional || count_of_expected_events > 0
|
||||
assert (optional_ || count_of_expected_events > 0
|
||||
|| client_closed_connection);
|
||||
|
||||
return count_of_expected_events;
|
||||
@ -507,14 +508,14 @@ int expect_monitor_event_multiple (void *server_mon,
|
||||
|
||||
#endif
|
||||
|
||||
void setup_handshake_socket_monitor (void *ctx,
|
||||
void *server,
|
||||
void **server_mon,
|
||||
const char *monitor_endpoint)
|
||||
void setup_handshake_socket_monitor (void *ctx_,
|
||||
void *server_,
|
||||
void **server_mon_,
|
||||
const char *monitor_endpoint_)
|
||||
{
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
// Monitor handshake events on the server
|
||||
int rc = zmq_socket_monitor (server, monitor_endpoint,
|
||||
int rc = zmq_socket_monitor (server_, monitor_endpoint_,
|
||||
ZMQ_EVENT_HANDSHAKE_SUCCEEDED
|
||||
| ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL
|
||||
| ZMQ_EVENT_HANDSHAKE_FAILED_AUTH
|
||||
@ -522,160 +523,160 @@ void setup_handshake_socket_monitor (void *ctx,
|
||||
assert (rc == 0);
|
||||
|
||||
// Create socket for collecting monitor events
|
||||
*server_mon = zmq_socket (ctx, ZMQ_PAIR);
|
||||
assert (*server_mon);
|
||||
*server_mon_ = zmq_socket (ctx_, ZMQ_PAIR);
|
||||
assert (*server_mon_);
|
||||
int linger = 0;
|
||||
rc = zmq_setsockopt (*server_mon, ZMQ_LINGER, &linger, sizeof (linger));
|
||||
rc = zmq_setsockopt (*server_mon_, ZMQ_LINGER, &linger, sizeof (linger));
|
||||
assert (rc == 0);
|
||||
|
||||
// Connect it to the inproc endpoints so they'll get events
|
||||
rc = zmq_connect (*server_mon, monitor_endpoint);
|
||||
rc = zmq_connect (*server_mon_, monitor_endpoint_);
|
||||
assert (rc == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void setup_context_and_server_side (
|
||||
void **ctx,
|
||||
void **zap_control,
|
||||
void **zap_thread,
|
||||
void **server,
|
||||
void **server_mon,
|
||||
char *my_endpoint,
|
||||
void **ctx_,
|
||||
void **zap_control_,
|
||||
void **zap_thread_,
|
||||
void **server_,
|
||||
void **server_mon_,
|
||||
char *my_endpoint_,
|
||||
zmq_thread_fn zap_handler_ = &zap_handler,
|
||||
socket_config_fn socket_config_ = &socket_config_curve_server,
|
||||
void *socket_config_data_ = valid_server_secret,
|
||||
const char *routing_id = "IDENT")
|
||||
const char *routing_id_ = "IDENT")
|
||||
{
|
||||
*ctx = zmq_ctx_new ();
|
||||
assert (*ctx);
|
||||
*ctx_ = zmq_ctx_new ();
|
||||
assert (*ctx_);
|
||||
|
||||
// Spawn ZAP handler
|
||||
zap_requests_handled = zmq_atomic_counter_new ();
|
||||
assert (zap_requests_handled != NULL);
|
||||
|
||||
*zap_control = zmq_socket (*ctx, ZMQ_REP);
|
||||
assert (*zap_control);
|
||||
int rc = zmq_bind (*zap_control, "inproc://handler-control");
|
||||
*zap_control_ = zmq_socket (*ctx_, ZMQ_REP);
|
||||
assert (*zap_control_);
|
||||
int rc = zmq_bind (*zap_control_, "inproc://handler-control");
|
||||
assert (rc == 0);
|
||||
int linger = 0;
|
||||
rc = zmq_setsockopt (*zap_control, ZMQ_LINGER, &linger, sizeof (linger));
|
||||
rc = zmq_setsockopt (*zap_control_, ZMQ_LINGER, &linger, sizeof (linger));
|
||||
assert (rc == 0);
|
||||
|
||||
if (zap_handler_ != NULL) {
|
||||
*zap_thread = zmq_threadstart (zap_handler_, *ctx);
|
||||
*zap_thread_ = zmq_threadstart (zap_handler_, *ctx_);
|
||||
|
||||
char *buf = s_recv (*zap_control);
|
||||
char *buf = s_recv (*zap_control_);
|
||||
assert (buf);
|
||||
assert (streq (buf, "GO"));
|
||||
free (buf);
|
||||
} else
|
||||
*zap_thread = NULL;
|
||||
*zap_thread_ = NULL;
|
||||
|
||||
// Server socket will accept connections
|
||||
*server = zmq_socket (*ctx, ZMQ_DEALER);
|
||||
assert (*server);
|
||||
rc = zmq_setsockopt (*server, ZMQ_LINGER, &linger, sizeof (linger));
|
||||
*server_ = zmq_socket (*ctx_, ZMQ_DEALER);
|
||||
assert (*server_);
|
||||
rc = zmq_setsockopt (*server_, ZMQ_LINGER, &linger, sizeof (linger));
|
||||
assert (rc == 0);
|
||||
|
||||
socket_config_ (*server, socket_config_data_);
|
||||
socket_config_ (*server_, socket_config_data_);
|
||||
|
||||
rc =
|
||||
zmq_setsockopt (*server, ZMQ_ROUTING_ID, routing_id, strlen (routing_id));
|
||||
rc = zmq_setsockopt (*server_, ZMQ_ROUTING_ID, routing_id_,
|
||||
strlen (routing_id_));
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_bind (*server, "tcp://127.0.0.1:*");
|
||||
rc = zmq_bind (*server_, "tcp://127.0.0.1:*");
|
||||
assert (rc == 0);
|
||||
|
||||
size_t len = MAX_SOCKET_STRING;
|
||||
rc = zmq_getsockopt (*server, ZMQ_LAST_ENDPOINT, my_endpoint, &len);
|
||||
rc = zmq_getsockopt (*server_, ZMQ_LAST_ENDPOINT, my_endpoint_, &len);
|
||||
assert (rc == 0);
|
||||
|
||||
const char server_monitor_endpoint[] = "inproc://monitor-server";
|
||||
setup_handshake_socket_monitor (*ctx, *server, server_mon,
|
||||
setup_handshake_socket_monitor (*ctx_, *server_, server_mon_,
|
||||
server_monitor_endpoint);
|
||||
}
|
||||
|
||||
void shutdown_context_and_server_side (void *ctx,
|
||||
void *zap_thread,
|
||||
void *server,
|
||||
void *server_mon,
|
||||
void *zap_control,
|
||||
bool zap_handler_stopped = false)
|
||||
void shutdown_context_and_server_side (void *ctx_,
|
||||
void *zap_thread_,
|
||||
void *server_,
|
||||
void *server_mon_,
|
||||
void *zap_control_,
|
||||
bool zap_handler_stopped_ = false)
|
||||
{
|
||||
if (zap_thread && !zap_handler_stopped) {
|
||||
int rc = s_send (zap_control, "STOP");
|
||||
if (zap_thread_ && !zap_handler_stopped_) {
|
||||
int rc = s_send (zap_control_, "STOP");
|
||||
assert (rc == 4);
|
||||
char *buf = s_recv (zap_control);
|
||||
char *buf = s_recv (zap_control_);
|
||||
assert (buf);
|
||||
assert (streq (buf, "STOPPED"));
|
||||
free (buf);
|
||||
rc = zmq_unbind (zap_control, "inproc://handler-control");
|
||||
rc = zmq_unbind (zap_control_, "inproc://handler-control");
|
||||
assert (rc == 0);
|
||||
}
|
||||
int rc = zmq_close (zap_control);
|
||||
int rc = zmq_close (zap_control_);
|
||||
assert (rc == 0);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
rc = zmq_close (server_mon);
|
||||
rc = zmq_close (server_mon_);
|
||||
assert (rc == 0);
|
||||
#endif
|
||||
rc = zmq_close (server);
|
||||
rc = zmq_close (server_);
|
||||
assert (rc == 0);
|
||||
|
||||
// Wait until ZAP handler terminates
|
||||
if (zap_thread)
|
||||
zmq_threadclose (zap_thread);
|
||||
if (zap_thread_)
|
||||
zmq_threadclose (zap_thread_);
|
||||
|
||||
rc = zmq_ctx_term (ctx);
|
||||
rc = zmq_ctx_term (ctx_);
|
||||
assert (rc == 0);
|
||||
|
||||
zmq_atomic_counter_destroy (&zap_requests_handled);
|
||||
}
|
||||
|
||||
void *create_and_connect_client (void *ctx,
|
||||
char *my_endpoint,
|
||||
void *create_and_connect_client (void *ctx_,
|
||||
char *my_endpoint_,
|
||||
socket_config_fn socket_config_,
|
||||
void *socket_config_data_,
|
||||
void **client_mon = NULL)
|
||||
void **client_mon_ = NULL)
|
||||
{
|
||||
void *client = zmq_socket (ctx, ZMQ_DEALER);
|
||||
void *client = zmq_socket (ctx_, ZMQ_DEALER);
|
||||
assert (client);
|
||||
|
||||
socket_config_ (client, socket_config_data_);
|
||||
|
||||
int rc = zmq_connect (client, my_endpoint);
|
||||
int rc = zmq_connect (client, my_endpoint_);
|
||||
assert (rc == 0);
|
||||
|
||||
if (client_mon) {
|
||||
setup_handshake_socket_monitor (ctx, client, client_mon,
|
||||
if (client_mon_) {
|
||||
setup_handshake_socket_monitor (ctx_, client, client_mon_,
|
||||
"inproc://client-monitor");
|
||||
}
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
void expect_new_client_bounce_fail (void *ctx,
|
||||
char *my_endpoint,
|
||||
void *server,
|
||||
void expect_new_client_bounce_fail (void *ctx_,
|
||||
char *my_endpoint_,
|
||||
void *server_,
|
||||
socket_config_fn socket_config_,
|
||||
void *socket_config_data_,
|
||||
void **client_mon = NULL,
|
||||
int expected_client_event = 0,
|
||||
int expected_client_value = 0)
|
||||
void **client_mon_ = NULL,
|
||||
int expected_client_event_ = 0,
|
||||
int expected_client_value_ = 0)
|
||||
{
|
||||
void *my_client_mon;
|
||||
assert (client_mon == NULL || expected_client_event == 0);
|
||||
if (expected_client_event != 0)
|
||||
client_mon = &my_client_mon;
|
||||
void *client = create_and_connect_client (ctx, my_endpoint, socket_config_,
|
||||
socket_config_data_, client_mon);
|
||||
expect_bounce_fail (server, client);
|
||||
assert (client_mon_ == NULL || expected_client_event_ == 0);
|
||||
if (expected_client_event_ != 0)
|
||||
client_mon_ = &my_client_mon;
|
||||
void *client = create_and_connect_client (
|
||||
ctx_, my_endpoint_, socket_config_, socket_config_data_, client_mon_);
|
||||
expect_bounce_fail (server_, client);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
if (expected_client_event != 0) {
|
||||
if (expected_client_event_ != 0) {
|
||||
int events_received = 0;
|
||||
events_received = expect_monitor_event_multiple (
|
||||
my_client_mon, expected_client_event, expected_client_value, false);
|
||||
my_client_mon, expected_client_event_, expected_client_value_, false);
|
||||
|
||||
assert (events_received == 1);
|
||||
|
||||
|
@ -40,28 +40,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
int test_assert_success_message_errno_helper (int rc,
|
||||
const char *msg,
|
||||
const char *expr)
|
||||
int test_assert_success_message_errno_helper (int rc_,
|
||||
const char *msg_,
|
||||
const char *expr_)
|
||||
{
|
||||
if (rc == -1) {
|
||||
if (rc_ == -1) {
|
||||
char buffer[512];
|
||||
buffer[sizeof (buffer) - 1] =
|
||||
0; // to ensure defined behavior with VC++ <= 2013
|
||||
snprintf (buffer, sizeof (buffer) - 1,
|
||||
"%s failed%s%s%s, errno = %i (%s)", expr,
|
||||
msg ? " (additional info: " : "", msg ? msg : "",
|
||||
msg ? ")" : "", zmq_errno (), zmq_strerror (zmq_errno ()));
|
||||
"%s failed%s%s%s, errno = %i (%s)", expr_,
|
||||
msg_ ? " (additional info: " : "", msg_ ? msg_ : "",
|
||||
msg_ ? ")" : "", zmq_errno (), zmq_strerror (zmq_errno ()));
|
||||
TEST_FAIL_MESSAGE (buffer);
|
||||
}
|
||||
return rc;
|
||||
return rc_;
|
||||
}
|
||||
|
||||
int test_assert_success_message_raw_errno_helper (int rc,
|
||||
const char *msg,
|
||||
const char *expr)
|
||||
int test_assert_success_message_raw_errno_helper (int rc_,
|
||||
const char *msg_,
|
||||
const char *expr_)
|
||||
{
|
||||
if (rc == -1) {
|
||||
if (rc_ == -1) {
|
||||
#if defined ZMQ_HAVE_WINDOWS
|
||||
int current_errno = WSAGetLastError ();
|
||||
#else
|
||||
@ -72,11 +72,11 @@ int test_assert_success_message_raw_errno_helper (int rc,
|
||||
buffer[sizeof (buffer) - 1] =
|
||||
0; // to ensure defined behavior with VC++ <= 2013
|
||||
snprintf (buffer, sizeof (buffer) - 1, "%s failed%s%s%s, errno = %i",
|
||||
expr, msg ? " (additional info: " : "", msg ? msg : "",
|
||||
msg ? ")" : "", current_errno);
|
||||
expr_, msg_ ? " (additional info: " : "", msg_ ? msg_ : "",
|
||||
msg_ ? ")" : "", current_errno);
|
||||
TEST_FAIL_MESSAGE (buffer);
|
||||
}
|
||||
return rc;
|
||||
return rc_;
|
||||
}
|
||||
|
||||
#define TEST_ASSERT_SUCCESS_MESSAGE_ERRNO(expr, msg) \
|
||||
@ -95,16 +95,16 @@ int test_assert_success_message_raw_errno_helper (int rc,
|
||||
TEST_ASSERT_EQUAL_INT (error_code, errno); \
|
||||
}
|
||||
|
||||
void send_string_expect_success (void *socket, const char *str, int flags)
|
||||
void send_string_expect_success (void *socket_, const char *str_, int flags_)
|
||||
{
|
||||
const size_t len = str ? strlen (str) : 0;
|
||||
const int rc = zmq_send (socket, str, len, flags);
|
||||
const size_t len = str_ ? strlen (str_) : 0;
|
||||
const int rc = zmq_send (socket_, str_, len, flags_);
|
||||
TEST_ASSERT_EQUAL_INT ((int) len, rc);
|
||||
}
|
||||
|
||||
void recv_string_expect_success (void *socket, const char *str, int flags)
|
||||
void recv_string_expect_success (void *socket_, const char *str_, int flags_)
|
||||
{
|
||||
const size_t len = str ? strlen (str) : 0;
|
||||
const size_t len = str_ ? strlen (str_) : 0;
|
||||
char buffer[255];
|
||||
TEST_ASSERT_LESS_OR_EQUAL_MESSAGE (sizeof (buffer), len,
|
||||
"recv_string_expect_success cannot be "
|
||||
@ -112,22 +112,22 @@ void recv_string_expect_success (void *socket, const char *str, int flags)
|
||||
"characters");
|
||||
|
||||
const int rc = TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_recv (socket, buffer, sizeof (buffer), flags));
|
||||
zmq_recv (socket_, buffer, sizeof (buffer), flags_));
|
||||
TEST_ASSERT_EQUAL_INT ((int) len, rc);
|
||||
if (str)
|
||||
TEST_ASSERT_EQUAL_STRING_LEN (str, buffer, len);
|
||||
if (str_)
|
||||
TEST_ASSERT_EQUAL_STRING_LEN (str_, buffer, len);
|
||||
}
|
||||
|
||||
// do not call from tests directly, use setup_test_context, get_test_context and teardown_test_context only
|
||||
void *internal_manage_test_context (bool init, bool clear)
|
||||
void *internal_manage_test_context (bool init_, bool clear_)
|
||||
{
|
||||
static void *test_context = NULL;
|
||||
if (clear) {
|
||||
if (clear_) {
|
||||
TEST_ASSERT_NOT_NULL (test_context);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_ctx_term (test_context));
|
||||
test_context = NULL;
|
||||
} else {
|
||||
if (init) {
|
||||
if (init_) {
|
||||
TEST_ASSERT_NULL (test_context);
|
||||
test_context = zmq_ctx_new ();
|
||||
TEST_ASSERT_NOT_NULL (test_context);
|
||||
@ -138,12 +138,12 @@ void *internal_manage_test_context (bool init, bool clear)
|
||||
|
||||
#define MAX_TEST_SOCKETS 128
|
||||
|
||||
void internal_manage_test_sockets (void *socket, bool add)
|
||||
void internal_manage_test_sockets (void *socket_, bool add_)
|
||||
{
|
||||
static void *test_sockets[MAX_TEST_SOCKETS];
|
||||
static size_t test_socket_count = 0;
|
||||
if (!socket) {
|
||||
assert (!add);
|
||||
if (!socket_) {
|
||||
assert (!add_);
|
||||
|
||||
// force-close all sockets
|
||||
if (test_socket_count) {
|
||||
@ -157,17 +157,17 @@ void internal_manage_test_sockets (void *socket, bool add)
|
||||
test_socket_count = 0;
|
||||
}
|
||||
} else {
|
||||
if (add) {
|
||||
if (add_) {
|
||||
++test_socket_count;
|
||||
TEST_ASSERT_LESS_THAN_MESSAGE (MAX_TEST_SOCKETS, test_socket_count,
|
||||
"MAX_TEST_SOCKETS must be "
|
||||
"increased, or you cannot use the "
|
||||
"test context");
|
||||
test_sockets[test_socket_count - 1] = socket;
|
||||
test_sockets[test_socket_count - 1] = socket_;
|
||||
} else {
|
||||
bool found = false;
|
||||
for (size_t i = 0; i < test_socket_count; ++i) {
|
||||
if (test_sockets[i] == socket) {
|
||||
if (test_sockets[i] == socket_) {
|
||||
found = true;
|
||||
}
|
||||
if (found) {
|
||||
@ -202,53 +202,53 @@ void teardown_test_context ()
|
||||
}
|
||||
}
|
||||
|
||||
void *test_context_socket (int type)
|
||||
void *test_context_socket (int type_)
|
||||
{
|
||||
void *const socket = zmq_socket (get_test_context (), type);
|
||||
void *const socket = zmq_socket (get_test_context (), type_);
|
||||
TEST_ASSERT_NOT_NULL (socket);
|
||||
internal_manage_test_sockets (socket, true);
|
||||
return socket;
|
||||
}
|
||||
|
||||
void *test_context_socket_close (void *socket)
|
||||
void *test_context_socket_close (void *socket_)
|
||||
{
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_close (socket));
|
||||
internal_manage_test_sockets (socket, false);
|
||||
return socket;
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_close (socket_));
|
||||
internal_manage_test_sockets (socket_, false);
|
||||
return socket_;
|
||||
}
|
||||
|
||||
void *test_context_socket_close_zero_linger (void *socket)
|
||||
void *test_context_socket_close_zero_linger (void *socket_)
|
||||
{
|
||||
const int linger = 0;
|
||||
int rc = zmq_setsockopt (socket, ZMQ_LINGER, &linger, sizeof (linger));
|
||||
int rc = zmq_setsockopt (socket_, ZMQ_LINGER, &linger, sizeof (linger));
|
||||
TEST_ASSERT_TRUE (rc == 0 || zmq_errno () == ETERM);
|
||||
return test_context_socket_close (socket);
|
||||
return test_context_socket_close (socket_);
|
||||
}
|
||||
|
||||
void test_bind (void *socket,
|
||||
const char *bind_address,
|
||||
char *my_endpoint,
|
||||
size_t len)
|
||||
void test_bind (void *socket_,
|
||||
const char *bind_address_,
|
||||
char *my_endpoint_,
|
||||
size_t len_)
|
||||
{
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (socket, bind_address));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (socket_, bind_address_));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_getsockopt (socket, ZMQ_LAST_ENDPOINT, my_endpoint, &len));
|
||||
zmq_getsockopt (socket_, ZMQ_LAST_ENDPOINT, my_endpoint_, &len_));
|
||||
}
|
||||
|
||||
void bind_loopback (void *socket, int ipv6, char *my_endpoint, size_t len)
|
||||
void bind_loopback (void *socket_, int ipv6_, char *my_endpoint_, size_t len_)
|
||||
{
|
||||
if (ipv6 && !is_ipv6_available ()) {
|
||||
if (ipv6_ && !is_ipv6_available ()) {
|
||||
TEST_IGNORE_MESSAGE ("ipv6 is not available");
|
||||
}
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (socket, ZMQ_IPV6, &ipv6, sizeof (int)));
|
||||
zmq_setsockopt (socket_, ZMQ_IPV6, &ipv6_, sizeof (int)));
|
||||
|
||||
test_bind (socket, ipv6 ? "tcp://[::1]:*" : "tcp://127.0.0.1:*",
|
||||
my_endpoint, len);
|
||||
test_bind (socket_, ipv6_ ? "tcp://[::1]:*" : "tcp://127.0.0.1:*",
|
||||
my_endpoint_, len_);
|
||||
}
|
||||
|
||||
void bind_loopback_ipv4 (void *socket, char *my_endpoint, size_t len)
|
||||
void bind_loopback_ipv4 (void *socket_, char *my_endpoint_, size_t len_)
|
||||
{
|
||||
bind_loopback (socket, false, my_endpoint, len);
|
||||
bind_loopback (socket_, false, my_endpoint_, len_);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user