Problem: code from bind_loopback_ipv4 is duplicated

Solution: call bind_loopback_ipv4 where applicable
This commit is contained in:
Simon Giesecke 2019-03-24 13:17:22 -04:00
parent 8dc933f2ed
commit 7f64b925aa
7 changed files with 11 additions and 36 deletions

View File

@ -34,8 +34,6 @@ SETUP_TEARDOWN_TESTCONTEXT
void test_conflate () void test_conflate ()
{ {
const char *bind_to = "tcp://127.0.0.1:*";
size_t len = MAX_SOCKET_STRING;
char my_endpoint[MAX_SOCKET_STRING]; char my_endpoint[MAX_SOCKET_STRING];
int rc; int rc;
@ -45,9 +43,7 @@ void test_conflate ()
int conflate = 1; int conflate = 1;
TEST_ASSERT_SUCCESS_ERRNO ( TEST_ASSERT_SUCCESS_ERRNO (
zmq_setsockopt (s_in, ZMQ_CONFLATE, &conflate, sizeof (conflate))); zmq_setsockopt (s_in, ZMQ_CONFLATE, &conflate, sizeof (conflate)));
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (s_in, bind_to)); bind_loopback_ipv4 (s_in, my_endpoint, sizeof my_endpoint);
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (s_in, ZMQ_LAST_ENDPOINT, my_endpoint, &len));
void *s_out = test_context_socket (ZMQ_PUSH); void *s_out = test_context_socket (ZMQ_PUSH);

View File

@ -168,13 +168,10 @@ void test_ctx_zero_copy ()
// Create a TCP socket pair using the context and test that messages can be // 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. // received. Note that inproc sockets cannot be used for this test.
void *pull = zmq_socket (get_test_context (), ZMQ_PULL); void *pull = zmq_socket (get_test_context (), ZMQ_PULL);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pull, "tcp://127.0.0.1:*")); char endpoint[MAX_SOCKET_STRING];
bind_loopback_ipv4 (pull, endpoint, sizeof endpoint);
void *push = zmq_socket (get_test_context (), ZMQ_PUSH); void *push = zmq_socket (get_test_context (), ZMQ_PUSH);
size_t endpoint_len = MAX_SOCKET_STRING;
char endpoint[MAX_SOCKET_STRING];
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (pull, ZMQ_LAST_ENDPOINT, endpoint, &endpoint_len));
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (push, endpoint)); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (push, endpoint));
const char *small_str = "abcd"; const char *small_str = "abcd";

View File

@ -40,14 +40,11 @@ SETUP_TEARDOWN_TESTCONTEXT
int test_defaults (int send_hwm_, int msg_cnt_, const char *endpoint) int test_defaults (int send_hwm_, int msg_cnt_, const char *endpoint)
{ {
size_t len = SOCKET_STRING_LEN;
char pub_endpoint[SOCKET_STRING_LEN]; char pub_endpoint[SOCKET_STRING_LEN];
// Set up and bind XPUB socket // Set up and bind XPUB socket
void *pub_socket = test_context_socket (ZMQ_XPUB); void *pub_socket = test_context_socket (ZMQ_XPUB);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pub_socket, endpoint)); test_bind (pub_socket, endpoint, pub_endpoint, sizeof pub_endpoint);
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (pub_socket, ZMQ_LAST_ENDPOINT, pub_endpoint, &len));
// Set up and connect SUB socket // Set up and connect SUB socket
void *sub_socket = test_context_socket (ZMQ_SUB); void *sub_socket = test_context_socket (ZMQ_SUB);

View File

@ -72,15 +72,12 @@ void test_reconnect_ivl_ipc (void)
} }
#endif #endif
void test_reconnect_ivl_tcp (const char *address_) void test_reconnect_ivl_tcp (bind_function_t bind_function_)
{ {
size_t len = MAX_SOCKET_STRING;
char my_endpoint[MAX_SOCKET_STRING]; char my_endpoint[MAX_SOCKET_STRING];
void *sb = test_context_socket (ZMQ_PAIR); void *sb = test_context_socket (ZMQ_PAIR);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, address_)); bind_function_ (sb, my_endpoint, sizeof my_endpoint);
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, my_endpoint, &len));
test_reconnect_ivl_against_pair_socket (my_endpoint, sb); test_reconnect_ivl_against_pair_socket (my_endpoint, sb);
test_context_socket_close (sb); test_context_socket_close (sb);
@ -88,14 +85,14 @@ void test_reconnect_ivl_tcp (const char *address_)
void test_reconnect_ivl_tcp_ipv4 () void test_reconnect_ivl_tcp_ipv4 ()
{ {
test_reconnect_ivl_tcp ("tcp://127.0.0.1:*"); test_reconnect_ivl_tcp (bind_loopback_ipv4);
} }
void test_reconnect_ivl_tcp_ipv6 () void test_reconnect_ivl_tcp_ipv6 ()
{ {
if (is_ipv6_available ()) { if (is_ipv6_available ()) {
zmq_ctx_set (get_test_context (), ZMQ_IPV6, 1); zmq_ctx_set (get_test_context (), ZMQ_IPV6, 1);
test_reconnect_ivl_tcp ("tcp://[::1]:*"); test_reconnect_ivl_tcp (bind_loopback_ipv6);
} }
} }

View File

@ -34,14 +34,9 @@ SETUP_TEARDOWN_TESTCONTEXT
void test_with_handover () void test_with_handover ()
{ {
size_t len = MAX_SOCKET_STRING;
char my_endpoint[MAX_SOCKET_STRING]; char my_endpoint[MAX_SOCKET_STRING];
void *router = test_context_socket (ZMQ_ROUTER); void *router = test_context_socket (ZMQ_ROUTER);
bind_loopback_ipv4 (router, my_endpoint, sizeof my_endpoint);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (router, "tcp://127.0.0.1:*"));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (router, ZMQ_LAST_ENDPOINT, my_endpoint, &len));
// Enable the handover flag // Enable the handover flag
int handover = 1; int handover = 1;

View File

@ -184,13 +184,9 @@ void test_get_peer_state_corner_cases ()
void test_basic () void test_basic ()
{ {
size_t len = MAX_SOCKET_STRING;
char my_endpoint[MAX_SOCKET_STRING]; char my_endpoint[MAX_SOCKET_STRING];
void *router = test_context_socket (ZMQ_ROUTER); void *router = test_context_socket (ZMQ_ROUTER);
bind_loopback_ipv4 (router, my_endpoint, sizeof my_endpoint);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (router, "tcp://127.0.0.1:*"));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (router, ZMQ_LAST_ENDPOINT, my_endpoint, &len));
// Send a message to an unknown peer with the default setting // Send a message to an unknown peer with the default setting
// This will not report any error // This will not report any error

View File

@ -43,13 +43,10 @@ void client_thread (void *client_)
void test_thread_safe () void test_thread_safe ()
{ {
size_t len = MAX_SOCKET_STRING;
char my_endpoint[MAX_SOCKET_STRING]; char my_endpoint[MAX_SOCKET_STRING];
void *server = test_context_socket (ZMQ_SERVER); void *server = test_context_socket (ZMQ_SERVER);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (server, "tcp://127.0.0.1:*")); bind_loopback_ipv4 (server, my_endpoint, sizeof my_endpoint);
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (server, ZMQ_LAST_ENDPOINT, my_endpoint, &len));
void *client = test_context_socket (ZMQ_CLIENT); void *client = test_context_socket (ZMQ_CLIENT);