mirror of
https://github.com/zeromq/libzmq.git
synced 2025-11-07 05:58:45 +01:00
Problem: duplicated code in tests related to monitoring
Solution: extract new receive_monitor_address function
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
*/
|
||||
|
||||
#include "testutil.hpp"
|
||||
#include "testutil_monitoring.hpp"
|
||||
#include "testutil_unity.hpp"
|
||||
#if defined(ZMQ_HAVE_WINDOWS)
|
||||
#include <winsock2.h>
|
||||
@@ -178,43 +179,6 @@ void tearDown ()
|
||||
zmq_threadclose (zap_thread);
|
||||
}
|
||||
|
||||
// Read one event off the monitor socket; return value and address
|
||||
// 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_)
|
||||
{
|
||||
// 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)
|
||||
return -1; // Interruped, presumably
|
||||
TEST_ASSERT_TRUE (zmq_msg_more (&msg));
|
||||
|
||||
uint8_t *data = static_cast<uint8_t *> (zmq_msg_data (&msg));
|
||||
uint16_t event = *reinterpret_cast<uint16_t *> (data);
|
||||
if (value_)
|
||||
*value_ = *reinterpret_cast<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)
|
||||
return -1; // Interruped, presumably
|
||||
TEST_ASSERT_FALSE (zmq_msg_more (&msg));
|
||||
|
||||
if (address_) {
|
||||
const uint8_t *const data =
|
||||
static_cast<const uint8_t *> (zmq_msg_data (&msg));
|
||||
const size_t size = zmq_msg_size (&msg);
|
||||
*address_ = static_cast<char *> (malloc (size + 1));
|
||||
memcpy (*address_, data, size);
|
||||
*address_[size] = 0;
|
||||
}
|
||||
zmq_msg_close (&msg);
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
void test_valid_creds ()
|
||||
{
|
||||
void *client = test_context_socket (ZMQ_DEALER);
|
||||
|
||||
Reference in New Issue
Block a user