mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-12 10:33:52 +01:00
Problem: code from bind_loopback_ipv4 is duplicated
Solution: call bind_loopback_ipv4 where applicable
This commit is contained in:
parent
8dc933f2ed
commit
7f64b925aa
@ -34,8 +34,6 @@ SETUP_TEARDOWN_TESTCONTEXT
|
||||
|
||||
void test_conflate ()
|
||||
{
|
||||
const char *bind_to = "tcp://127.0.0.1:*";
|
||||
size_t len = MAX_SOCKET_STRING;
|
||||
char my_endpoint[MAX_SOCKET_STRING];
|
||||
|
||||
int rc;
|
||||
@ -45,9 +43,7 @@ void test_conflate ()
|
||||
int conflate = 1;
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_setsockopt (s_in, ZMQ_CONFLATE, &conflate, sizeof (conflate)));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (s_in, bind_to));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_getsockopt (s_in, ZMQ_LAST_ENDPOINT, my_endpoint, &len));
|
||||
bind_loopback_ipv4 (s_in, my_endpoint, sizeof my_endpoint);
|
||||
|
||||
void *s_out = test_context_socket (ZMQ_PUSH);
|
||||
|
||||
|
@ -168,13 +168,10 @@ void test_ctx_zero_copy ()
|
||||
// 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 (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);
|
||||
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));
|
||||
|
||||
const char *small_str = "abcd";
|
||||
|
@ -40,14 +40,11 @@ SETUP_TEARDOWN_TESTCONTEXT
|
||||
|
||||
int test_defaults (int send_hwm_, int msg_cnt_, const char *endpoint)
|
||||
{
|
||||
size_t len = SOCKET_STRING_LEN;
|
||||
char pub_endpoint[SOCKET_STRING_LEN];
|
||||
|
||||
// Set up and bind XPUB socket
|
||||
void *pub_socket = test_context_socket (ZMQ_XPUB);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pub_socket, endpoint));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_getsockopt (pub_socket, ZMQ_LAST_ENDPOINT, pub_endpoint, &len));
|
||||
test_bind (pub_socket, endpoint, pub_endpoint, sizeof pub_endpoint);
|
||||
|
||||
// Set up and connect SUB socket
|
||||
void *sub_socket = test_context_socket (ZMQ_SUB);
|
||||
|
@ -72,15 +72,12 @@ void test_reconnect_ivl_ipc (void)
|
||||
}
|
||||
#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];
|
||||
|
||||
void *sb = test_context_socket (ZMQ_PAIR);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, address_));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, my_endpoint, &len));
|
||||
bind_function_ (sb, my_endpoint, sizeof my_endpoint);
|
||||
|
||||
test_reconnect_ivl_against_pair_socket (my_endpoint, sb);
|
||||
test_context_socket_close (sb);
|
||||
@ -88,14 +85,14 @@ void test_reconnect_ivl_tcp (const char *address_)
|
||||
|
||||
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 ()
|
||||
{
|
||||
if (is_ipv6_available ()) {
|
||||
zmq_ctx_set (get_test_context (), ZMQ_IPV6, 1);
|
||||
test_reconnect_ivl_tcp ("tcp://[::1]:*");
|
||||
test_reconnect_ivl_tcp (bind_loopback_ipv6);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,14 +34,9 @@ SETUP_TEARDOWN_TESTCONTEXT
|
||||
|
||||
void test_with_handover ()
|
||||
{
|
||||
size_t len = MAX_SOCKET_STRING;
|
||||
char my_endpoint[MAX_SOCKET_STRING];
|
||||
void *router = test_context_socket (ZMQ_ROUTER);
|
||||
|
||||
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));
|
||||
bind_loopback_ipv4 (router, my_endpoint, sizeof my_endpoint);
|
||||
|
||||
// Enable the handover flag
|
||||
int handover = 1;
|
||||
|
@ -184,13 +184,9 @@ void test_get_peer_state_corner_cases ()
|
||||
|
||||
void test_basic ()
|
||||
{
|
||||
size_t len = MAX_SOCKET_STRING;
|
||||
char my_endpoint[MAX_SOCKET_STRING];
|
||||
void *router = test_context_socket (ZMQ_ROUTER);
|
||||
|
||||
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));
|
||||
bind_loopback_ipv4 (router, my_endpoint, sizeof my_endpoint);
|
||||
|
||||
// Send a message to an unknown peer with the default setting
|
||||
// This will not report any error
|
||||
|
@ -43,13 +43,10 @@ void client_thread (void *client_)
|
||||
|
||||
void test_thread_safe ()
|
||||
{
|
||||
size_t len = MAX_SOCKET_STRING;
|
||||
char my_endpoint[MAX_SOCKET_STRING];
|
||||
|
||||
void *server = test_context_socket (ZMQ_SERVER);
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (server, "tcp://127.0.0.1:*"));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (
|
||||
zmq_getsockopt (server, ZMQ_LAST_ENDPOINT, my_endpoint, &len));
|
||||
bind_loopback_ipv4 (server, my_endpoint, sizeof my_endpoint);
|
||||
|
||||
void *client = test_context_socket (ZMQ_CLIENT);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user