mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-13 10:52:56 +01:00
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.
This commit is contained in:
parent
797439c8e2
commit
19ff4d0b6a
@ -10,9 +10,7 @@ zmq_socket_monitor_versioned - monitor socket events
|
||||
|
||||
SYNOPSIS
|
||||
--------
|
||||
*int zmq_socket_monitor_versioned (void '*socket', char '*endpoint', uint64_t 'events', int 'event_version');*
|
||||
*int zmq_socket_monitor_versioned_typed (
|
||||
void '*socket', char '*endpoint', uint64_t 'events', int 'event_version', int 'type');*
|
||||
*int zmq_socket_monitor_versioned (void '*socket', char '*endpoint', uint64_t 'events', int 'event_version', int 'type');*
|
||||
|
||||
*int zmq_socket_monitor_pipes_stats (void '*socket');*
|
||||
|
||||
@ -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
|
||||
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.
|
||||
Supported types are 'ZMQ_PAIR' (which is the equivalent of
|
||||
_zmq_socket_monitor_versioned_), 'ZMQ_PUB' and 'ZMQ_PUSH'. Note that consumers
|
||||
Supported types are 'ZMQ_PAIR', 'ZMQ_PUB' and 'ZMQ_PUSH'. Note that consumers
|
||||
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'.
|
||||
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.
|
||||
The transport protocol of the monitor 'endpoint' is not supported. Monitor
|
||||
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*::
|
||||
The monitor 'endpoint' supplied does not exist or the specified socket 'type'
|
||||
is not supported.
|
||||
|
@ -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_V2 ZMQ_EVENT_ALL_V1 | ZMQ_EVENT_PIPES_STATS
|
||||
|
||||
ZMQ_EXPORT int zmq_socket_monitor_versioned (void *s_,
|
||||
const char *addr_,
|
||||
uint64_t events_,
|
||||
int event_version_);
|
||||
ZMQ_EXPORT int zmq_socket_monitor_versioned_typed (
|
||||
ZMQ_EXPORT int zmq_socket_monitor_versioned (
|
||||
void *s_, const char *addr_, uint64_t events_, int event_version_, int type_);
|
||||
ZMQ_EXPORT int zmq_socket_monitor_pipes_stats (void *s);
|
||||
|
||||
|
24
src/zmq.cpp
24
src/zmq.cpp
@ -267,32 +267,20 @@ int zmq_getsockopt (void *s_, int option_, void *optval_, size_t *optvallen_)
|
||||
return s->getsockopt (option_, optval_, optvallen_);
|
||||
}
|
||||
|
||||
int zmq_socket_monitor_versioned (void *s_,
|
||||
const char *addr_,
|
||||
uint64_t events_,
|
||||
int event_version_)
|
||||
{
|
||||
zmq::socket_base_t *s = as_socket_base_t (s_);
|
||||
if (!s)
|
||||
return -1;
|
||||
return s->monitor (addr_, events_, event_version_, ZMQ_PAIR);
|
||||
}
|
||||
|
||||
int zmq_socket_monitor (void *s_, const char *addr_, int events_)
|
||||
{
|
||||
return zmq_socket_monitor_versioned (s_, addr_, events_, 1);
|
||||
}
|
||||
|
||||
int zmq_socket_monitor_versioned_typed (
|
||||
int zmq_socket_monitor_versioned (
|
||||
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_socket_monitor (void *s_, const char *addr_, int events_)
|
||||
{
|
||||
return zmq_socket_monitor_versioned (s_, addr_, events_, 1, ZMQ_PAIR);
|
||||
}
|
||||
|
||||
int zmq_join (void *s_, const char *group_)
|
||||
{
|
||||
zmq::socket_base_t *s = as_socket_base_t (s_);
|
||||
|
@ -130,11 +130,7 @@ int zmq_socket_get_peer_state (void *socket_,
|
||||
#define ZMQ_EVENT_ALL_V1 ZMQ_EVENT_ALL
|
||||
#define ZMQ_EVENT_ALL_V2 ZMQ_EVENT_ALL_V1 | ZMQ_EVENT_PIPES_STATS
|
||||
|
||||
int zmq_socket_monitor_versioned (void *s_,
|
||||
const char *addr_,
|
||||
uint64_t events_,
|
||||
int event_version_);
|
||||
int zmq_socket_monitor_versioned_typed (
|
||||
int zmq_socket_monitor_versioned (
|
||||
void *s_, const char *addr_, uint64_t events_, int event_version_, int type_);
|
||||
int zmq_socket_monitor_pipes_stats (void *s_);
|
||||
|
||||
|
@ -126,21 +126,21 @@ void test_monitor_basic ()
|
||||
#if (defined ZMQ_CURRENT_EVENT_VERSION && ZMQ_CURRENT_EVENT_VERSION >= 2) \
|
||||
|| (defined ZMQ_CURRENT_EVENT_VERSION \
|
||||
&& 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);
|
||||
|
||||
// Socket monitoring only works with ZMQ_PAIR, ZMQ_PUB and ZMQ_PUSH.
|
||||
TEST_ASSERT_FAILURE_ERRNO (
|
||||
EINVAL, zmq_socket_monitor_versioned_typed (
|
||||
EINVAL, zmq_socket_monitor_versioned (
|
||||
client, "inproc://invalid-socket-type", 0, 2, ZMQ_CLIENT));
|
||||
|
||||
test_context_socket_close_zero_linger (client);
|
||||
}
|
||||
|
||||
void test_monitor_versioned_typed_basic (bind_function_t bind_function_,
|
||||
const char *expected_prefix_,
|
||||
int type_)
|
||||
void test_monitor_versioned_basic (bind_function_t bind_function_,
|
||||
const char *expected_prefix_,
|
||||
int type_)
|
||||
{
|
||||
char server_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_,
|
||||
void *server = test_context_socket (ZMQ_DEALER);
|
||||
|
||||
// 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_));
|
||||
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_));
|
||||
|
||||
// Choose the appropriate consumer socket type.
|
||||
@ -267,35 +267,33 @@ void test_monitor_versioned_typed_basic (bind_function_t bind_function_,
|
||||
void test_monitor_versioned_basic_tcp_ipv4 ()
|
||||
{
|
||||
static const char prefix[] = "tcp://127.0.0.1:";
|
||||
// Calling 'monitor_versioned_typed' with ZMQ_PAIR is the equivalent of
|
||||
// calling 'monitor_versioned'.
|
||||
test_monitor_versioned_typed_basic (bind_loopback_ipv4, prefix, ZMQ_PAIR);
|
||||
test_monitor_versioned_typed_basic (bind_loopback_ipv4, prefix, ZMQ_PUB);
|
||||
test_monitor_versioned_typed_basic (bind_loopback_ipv4, prefix, ZMQ_PUSH);
|
||||
test_monitor_versioned_basic (bind_loopback_ipv4, prefix, ZMQ_PAIR);
|
||||
test_monitor_versioned_basic (bind_loopback_ipv4, prefix, ZMQ_PUB);
|
||||
test_monitor_versioned_basic (bind_loopback_ipv4, prefix, ZMQ_PUSH);
|
||||
}
|
||||
|
||||
void test_monitor_versioned_basic_tcp_ipv6 ()
|
||||
{
|
||||
static const char prefix[] = "tcp://[::1]:";
|
||||
test_monitor_versioned_typed_basic (bind_loopback_ipv6, prefix, ZMQ_PAIR);
|
||||
test_monitor_versioned_typed_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_PAIR);
|
||||
test_monitor_versioned_basic (bind_loopback_ipv6, prefix, ZMQ_PUB);
|
||||
test_monitor_versioned_basic (bind_loopback_ipv6, prefix, ZMQ_PUSH);
|
||||
}
|
||||
|
||||
void test_monitor_versioned_basic_ipc ()
|
||||
{
|
||||
static const char prefix[] = "ipc://";
|
||||
test_monitor_versioned_typed_basic (bind_loopback_ipc, prefix, ZMQ_PAIR);
|
||||
test_monitor_versioned_typed_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_PAIR);
|
||||
test_monitor_versioned_basic (bind_loopback_ipc, prefix, ZMQ_PUB);
|
||||
test_monitor_versioned_basic (bind_loopback_ipc, prefix, ZMQ_PUSH);
|
||||
}
|
||||
|
||||
void test_monitor_versioned_basic_tipc ()
|
||||
{
|
||||
static const char prefix[] = "tipc://";
|
||||
test_monitor_versioned_typed_basic (bind_loopback_tipc, prefix, ZMQ_PAIR);
|
||||
test_monitor_versioned_typed_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_PAIR);
|
||||
test_monitor_versioned_basic (bind_loopback_tipc, prefix, ZMQ_PUB);
|
||||
test_monitor_versioned_basic (bind_loopback_tipc, prefix, ZMQ_PUSH);
|
||||
}
|
||||
|
||||
#ifdef ZMQ_EVENT_PIPES_STATS
|
||||
@ -310,7 +308,7 @@ void test_monitor_versioned_stats (bind_function_t bind_function_,
|
||||
void *push = test_context_socket (ZMQ_PUSH);
|
||||
|
||||
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
|
||||
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_socket_monitor_pipes_stats (push));
|
||||
@ -437,7 +435,7 @@ int main ()
|
||||
#if (defined ZMQ_CURRENT_EVENT_VERSION && ZMQ_CURRENT_EVENT_VERSION >= 2) \
|
||||
|| (defined ZMQ_CURRENT_EVENT_VERSION \
|
||||
&& 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_ipv6);
|
||||
RUN_TEST (test_monitor_versioned_basic_ipc);
|
||||
|
Loading…
Reference in New Issue
Block a user