Commit 779d120f authored by Simon Giesecke's avatar Simon Giesecke

Problem: tests do not follow naming style

Solution: apply naming style
parent d767909b
......@@ -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);
......
This diff is collapsed.
......@@ -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;
......
This diff is collapsed.
......@@ -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);
......
This diff is collapsed.
......@@ -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
......
This diff is collapsed.
......@@ -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
}
......
This diff is collapsed.
......@@ -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_);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment