Commit 19ff4d0b authored by Luca Boccassi's avatar Luca Boccassi

Problem: zmq_socket_monitor_versioned_typed duplicates zmq_socket_monitor_versioned

Solution: unify the two APIs, as they are both still in DRAFT state and
thus can be changed.
parent 797439c8
...@@ -10,9 +10,7 @@ zmq_socket_monitor_versioned - monitor socket events ...@@ -10,9 +10,7 @@ zmq_socket_monitor_versioned - monitor socket events
SYNOPSIS SYNOPSIS
-------- --------
*int zmq_socket_monitor_versioned (void '*socket', char '*endpoint', uint64_t 'events', int 'event_version');* *int zmq_socket_monitor_versioned (void '*socket', char '*endpoint', uint64_t 'events', int 'event_version', int 'type');*
*int zmq_socket_monitor_versioned_typed (
void '*socket', char '*endpoint', uint64_t 'events', int 'event_version', int 'type');*
*int zmq_socket_monitor_pipes_stats (void '*socket');* *int zmq_socket_monitor_pipes_stats (void '*socket');*
...@@ -58,11 +56,8 @@ connection uses a bound or connected local endpoint. ...@@ -58,11 +56,8 @@ connection uses a bound or connected local endpoint.
Note that the format of the second and further frames, and also the number of Note that the format of the second and further frames, and also the number of
frames, may be different for events added in the future. frames, may be different for events added in the future.
The _zmq_socket_monitor_versioned_typed()_ is a generalisation of
_zmq_socket_monitor_versioned_ that supports more monitoring socket types.
The 'type' argument is used to specify the type of the monitoring socket. The 'type' argument is used to specify the type of the monitoring socket.
Supported types are 'ZMQ_PAIR' (which is the equivalent of Supported types are 'ZMQ_PAIR', 'ZMQ_PUB' and 'ZMQ_PUSH'. Note that consumers
_zmq_socket_monitor_versioned_), 'ZMQ_PUB' and 'ZMQ_PUSH'. Note that consumers
of the events will have to be compatible with the socket type, for instance a of the events will have to be compatible with the socket type, for instance a
monitoring socket of type 'ZMQ_PUB' will require consumers of type 'ZMQ_SUB'. monitoring socket of type 'ZMQ_PUB' will require consumers of type 'ZMQ_SUB'.
In the case that the monitoring socket type is of 'ZMQ_PUB', the multipart In the case that the monitoring socket type is of 'ZMQ_PUB', the multipart
...@@ -224,19 +219,6 @@ The 0MQ 'context' associated with the specified 'socket' was terminated. ...@@ -224,19 +219,6 @@ The 0MQ 'context' associated with the specified 'socket' was terminated.
The transport protocol of the monitor 'endpoint' is not supported. Monitor The transport protocol of the monitor 'endpoint' is not supported. Monitor
sockets are required to use the inproc:// transport. sockets are required to use the inproc:// transport.
*EINVAL*::
The monitor 'endpoint' supplied does not exist.
ERRORS - _zmq_socket_monitor_typed()_
-------------------------------
*ETERM*::
The 0MQ 'context' associated with the specified 'socket' was terminated.
*EPROTONOSUPPORT*::
The transport protocol of the monitor 'endpoint' is not supported. Monitor
sockets are required to use the inproc:// transport.
*EINVAL*:: *EINVAL*::
The monitor 'endpoint' supplied does not exist or the specified socket 'type' The monitor 'endpoint' supplied does not exist or the specified socket 'type'
is not supported. is not supported.
......
...@@ -732,11 +732,7 @@ ZMQ_EXPORT int zmq_socket_get_peer_state (void *socket, ...@@ -732,11 +732,7 @@ ZMQ_EXPORT int zmq_socket_get_peer_state (void *socket,
#define ZMQ_EVENT_ALL_V1 ZMQ_EVENT_ALL #define ZMQ_EVENT_ALL_V1 ZMQ_EVENT_ALL
#define ZMQ_EVENT_ALL_V2 ZMQ_EVENT_ALL_V1 | ZMQ_EVENT_PIPES_STATS #define ZMQ_EVENT_ALL_V2 ZMQ_EVENT_ALL_V1 | ZMQ_EVENT_PIPES_STATS
ZMQ_EXPORT int zmq_socket_monitor_versioned (void *s_, ZMQ_EXPORT int zmq_socket_monitor_versioned (
const char *addr_,
uint64_t events_,
int event_version_);
ZMQ_EXPORT int zmq_socket_monitor_versioned_typed (
void *s_, const char *addr_, uint64_t events_, int event_version_, int type_); void *s_, const char *addr_, uint64_t events_, int event_version_, int type_);
ZMQ_EXPORT int zmq_socket_monitor_pipes_stats (void *s); ZMQ_EXPORT int zmq_socket_monitor_pipes_stats (void *s);
......
...@@ -267,30 +267,18 @@ int zmq_getsockopt (void *s_, int option_, void *optval_, size_t *optvallen_) ...@@ -267,30 +267,18 @@ int zmq_getsockopt (void *s_, int option_, void *optval_, size_t *optvallen_)
return s->getsockopt (option_, optval_, optvallen_); return s->getsockopt (option_, optval_, optvallen_);
} }
int zmq_socket_monitor_versioned (void *s_, int zmq_socket_monitor_versioned (
const char *addr_, void *s_, const char *addr_, uint64_t events_, int event_version_, int type_)
uint64_t events_,
int event_version_)
{ {
zmq::socket_base_t *s = as_socket_base_t (s_); zmq::socket_base_t *s = as_socket_base_t (s_);
if (!s) if (!s)
return -1; return -1;
return s->monitor (addr_, events_, event_version_, ZMQ_PAIR); return s->monitor (addr_, events_, event_version_, type_);
} }
int zmq_socket_monitor (void *s_, const char *addr_, int events_) int zmq_socket_monitor (void *s_, const char *addr_, int events_)
{ {
return zmq_socket_monitor_versioned (s_, addr_, events_, 1); return zmq_socket_monitor_versioned (s_, addr_, events_, 1, ZMQ_PAIR);
}
int zmq_socket_monitor_versioned_typed (
void *s_, const char *addr_, uint64_t events_, int event_version_, int type_)
{
zmq::socket_base_t *s = as_socket_base_t (s_);
if (!s)
return -1;
return s->monitor (addr_, events_, event_version_, type_);
} }
int zmq_join (void *s_, const char *group_) int zmq_join (void *s_, const char *group_)
......
...@@ -130,11 +130,7 @@ int zmq_socket_get_peer_state (void *socket_, ...@@ -130,11 +130,7 @@ int zmq_socket_get_peer_state (void *socket_,
#define ZMQ_EVENT_ALL_V1 ZMQ_EVENT_ALL #define ZMQ_EVENT_ALL_V1 ZMQ_EVENT_ALL
#define ZMQ_EVENT_ALL_V2 ZMQ_EVENT_ALL_V1 | ZMQ_EVENT_PIPES_STATS #define ZMQ_EVENT_ALL_V2 ZMQ_EVENT_ALL_V1 | ZMQ_EVENT_PIPES_STATS
int zmq_socket_monitor_versioned (void *s_, int zmq_socket_monitor_versioned (
const char *addr_,
uint64_t events_,
int event_version_);
int zmq_socket_monitor_versioned_typed (
void *s_, const char *addr_, uint64_t events_, int event_version_, int type_); void *s_, const char *addr_, uint64_t events_, int event_version_, int type_);
int zmq_socket_monitor_pipes_stats (void *s_); int zmq_socket_monitor_pipes_stats (void *s_);
......
...@@ -126,21 +126,21 @@ void test_monitor_basic () ...@@ -126,21 +126,21 @@ void test_monitor_basic ()
#if (defined ZMQ_CURRENT_EVENT_VERSION && ZMQ_CURRENT_EVENT_VERSION >= 2) \ #if (defined ZMQ_CURRENT_EVENT_VERSION && ZMQ_CURRENT_EVENT_VERSION >= 2) \
|| (defined ZMQ_CURRENT_EVENT_VERSION \ || (defined ZMQ_CURRENT_EVENT_VERSION \
&& ZMQ_CURRENT_EVENT_VERSION_DRAFT >= 2) && ZMQ_CURRENT_EVENT_VERSION_DRAFT >= 2)
void test_monitor_versioned_typed_invalid_socket_type () void test_monitor_versioned_invalid_socket_type ()
{ {
void *client = test_context_socket (ZMQ_DEALER); void *client = test_context_socket (ZMQ_DEALER);
// Socket monitoring only works with ZMQ_PAIR, ZMQ_PUB and ZMQ_PUSH. // Socket monitoring only works with ZMQ_PAIR, ZMQ_PUB and ZMQ_PUSH.
TEST_ASSERT_FAILURE_ERRNO ( TEST_ASSERT_FAILURE_ERRNO (
EINVAL, zmq_socket_monitor_versioned_typed ( EINVAL, zmq_socket_monitor_versioned (
client, "inproc://invalid-socket-type", 0, 2, ZMQ_CLIENT)); client, "inproc://invalid-socket-type", 0, 2, ZMQ_CLIENT));
test_context_socket_close_zero_linger (client); test_context_socket_close_zero_linger (client);
} }
void test_monitor_versioned_typed_basic (bind_function_t bind_function_, void test_monitor_versioned_basic (bind_function_t bind_function_,
const char *expected_prefix_, const char *expected_prefix_,
int type_) int type_)
{ {
char server_endpoint[MAX_SOCKET_STRING]; char server_endpoint[MAX_SOCKET_STRING];
char client_mon_endpoint[MAX_SOCKET_STRING]; char client_mon_endpoint[MAX_SOCKET_STRING];
...@@ -158,9 +158,9 @@ void test_monitor_versioned_typed_basic (bind_function_t bind_function_, ...@@ -158,9 +158,9 @@ void test_monitor_versioned_typed_basic (bind_function_t bind_function_,
void *server = test_context_socket (ZMQ_DEALER); void *server = test_context_socket (ZMQ_DEALER);
// Monitor all events on client and server sockets // Monitor all events on client and server sockets
TEST_ASSERT_SUCCESS_ERRNO (zmq_socket_monitor_versioned_typed ( TEST_ASSERT_SUCCESS_ERRNO (zmq_socket_monitor_versioned (
client, client_mon_endpoint, ZMQ_EVENT_ALL_V2, 2, type_)); client, client_mon_endpoint, ZMQ_EVENT_ALL_V2, 2, type_));
TEST_ASSERT_SUCCESS_ERRNO (zmq_socket_monitor_versioned_typed ( TEST_ASSERT_SUCCESS_ERRNO (zmq_socket_monitor_versioned (
server, server_mon_endpoint, ZMQ_EVENT_ALL_V2, 2, type_)); server, server_mon_endpoint, ZMQ_EVENT_ALL_V2, 2, type_));
// Choose the appropriate consumer socket type. // Choose the appropriate consumer socket type.
...@@ -267,35 +267,33 @@ void test_monitor_versioned_typed_basic (bind_function_t bind_function_, ...@@ -267,35 +267,33 @@ void test_monitor_versioned_typed_basic (bind_function_t bind_function_,
void test_monitor_versioned_basic_tcp_ipv4 () void test_monitor_versioned_basic_tcp_ipv4 ()
{ {
static const char prefix[] = "tcp://127.0.0.1:"; static const char prefix[] = "tcp://127.0.0.1:";
// Calling 'monitor_versioned_typed' with ZMQ_PAIR is the equivalent of test_monitor_versioned_basic (bind_loopback_ipv4, prefix, ZMQ_PAIR);
// calling 'monitor_versioned'. test_monitor_versioned_basic (bind_loopback_ipv4, prefix, ZMQ_PUB);
test_monitor_versioned_typed_basic (bind_loopback_ipv4, prefix, ZMQ_PAIR); test_monitor_versioned_basic (bind_loopback_ipv4, prefix, ZMQ_PUSH);
test_monitor_versioned_typed_basic (bind_loopback_ipv4, prefix, ZMQ_PUB);
test_monitor_versioned_typed_basic (bind_loopback_ipv4, prefix, ZMQ_PUSH);
} }
void test_monitor_versioned_basic_tcp_ipv6 () void test_monitor_versioned_basic_tcp_ipv6 ()
{ {
static const char prefix[] = "tcp://[::1]:"; static const char prefix[] = "tcp://[::1]:";
test_monitor_versioned_typed_basic (bind_loopback_ipv6, prefix, ZMQ_PAIR); test_monitor_versioned_basic (bind_loopback_ipv6, prefix, ZMQ_PAIR);
test_monitor_versioned_typed_basic (bind_loopback_ipv6, prefix, ZMQ_PUB); test_monitor_versioned_basic (bind_loopback_ipv6, prefix, ZMQ_PUB);
test_monitor_versioned_typed_basic (bind_loopback_ipv6, prefix, ZMQ_PUSH); test_monitor_versioned_basic (bind_loopback_ipv6, prefix, ZMQ_PUSH);
} }
void test_monitor_versioned_basic_ipc () void test_monitor_versioned_basic_ipc ()
{ {
static const char prefix[] = "ipc://"; static const char prefix[] = "ipc://";
test_monitor_versioned_typed_basic (bind_loopback_ipc, prefix, ZMQ_PAIR); test_monitor_versioned_basic (bind_loopback_ipc, prefix, ZMQ_PAIR);
test_monitor_versioned_typed_basic (bind_loopback_ipc, prefix, ZMQ_PUB); test_monitor_versioned_basic (bind_loopback_ipc, prefix, ZMQ_PUB);
test_monitor_versioned_typed_basic (bind_loopback_ipc, prefix, ZMQ_PUSH); test_monitor_versioned_basic (bind_loopback_ipc, prefix, ZMQ_PUSH);
} }
void test_monitor_versioned_basic_tipc () void test_monitor_versioned_basic_tipc ()
{ {
static const char prefix[] = "tipc://"; static const char prefix[] = "tipc://";
test_monitor_versioned_typed_basic (bind_loopback_tipc, prefix, ZMQ_PAIR); test_monitor_versioned_basic (bind_loopback_tipc, prefix, ZMQ_PAIR);
test_monitor_versioned_typed_basic (bind_loopback_tipc, prefix, ZMQ_PUB); test_monitor_versioned_basic (bind_loopback_tipc, prefix, ZMQ_PUB);
test_monitor_versioned_typed_basic (bind_loopback_tipc, prefix, ZMQ_PUSH); test_monitor_versioned_basic (bind_loopback_tipc, prefix, ZMQ_PUSH);
} }
#ifdef ZMQ_EVENT_PIPES_STATS #ifdef ZMQ_EVENT_PIPES_STATS
...@@ -310,7 +308,7 @@ void test_monitor_versioned_stats (bind_function_t bind_function_, ...@@ -310,7 +308,7 @@ void test_monitor_versioned_stats (bind_function_t bind_function_,
void *push = test_context_socket (ZMQ_PUSH); void *push = test_context_socket (ZMQ_PUSH);
TEST_ASSERT_SUCCESS_ERRNO (zmq_socket_monitor_versioned ( TEST_ASSERT_SUCCESS_ERRNO (zmq_socket_monitor_versioned (
push, "inproc://monitor-push", ZMQ_EVENT_PIPES_STATS, 2)); push, "inproc://monitor-push", ZMQ_EVENT_PIPES_STATS, 2, ZMQ_PAIR));
// Should fail if there are no pipes to monitor // Should fail if there are no pipes to monitor
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_socket_monitor_pipes_stats (push)); TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_socket_monitor_pipes_stats (push));
...@@ -437,7 +435,7 @@ int main () ...@@ -437,7 +435,7 @@ int main ()
#if (defined ZMQ_CURRENT_EVENT_VERSION && ZMQ_CURRENT_EVENT_VERSION >= 2) \ #if (defined ZMQ_CURRENT_EVENT_VERSION && ZMQ_CURRENT_EVENT_VERSION >= 2) \
|| (defined ZMQ_CURRENT_EVENT_VERSION \ || (defined ZMQ_CURRENT_EVENT_VERSION \
&& ZMQ_CURRENT_EVENT_VERSION_DRAFT >= 2) && ZMQ_CURRENT_EVENT_VERSION_DRAFT >= 2)
RUN_TEST (test_monitor_versioned_typed_invalid_socket_type); RUN_TEST (test_monitor_versioned_invalid_socket_type);
RUN_TEST (test_monitor_versioned_basic_tcp_ipv4); RUN_TEST (test_monitor_versioned_basic_tcp_ipv4);
RUN_TEST (test_monitor_versioned_basic_tcp_ipv6); RUN_TEST (test_monitor_versioned_basic_tcp_ipv6);
RUN_TEST (test_monitor_versioned_basic_ipc); RUN_TEST (test_monitor_versioned_basic_ipc);
......
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