diff --git a/Makefile.am b/Makefile.am index 08016a0b..bae8424b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -470,7 +470,8 @@ tests_test_hwm_LDADD = src/libzmq.la ${UNITY_LIBS} tests_test_hwm_CPPFLAGS = ${UNITY_CPPFLAGS} tests_test_hwm_pubsub_SOURCES = tests/test_hwm_pubsub.cpp -tests_test_hwm_pubsub_LDADD = src/libzmq.la +tests_test_hwm_pubsub_LDADD = src/libzmq.la ${UNITY_LIBS} +tests_test_hwm_pubsub_CPPFLAGS = ${UNITY_CPPFLAGS} tests_test_reqrep_device_SOURCES = tests/test_reqrep_device.cpp tests_test_reqrep_device_LDADD = src/libzmq.la @@ -629,7 +630,8 @@ tests_test_capabilities_SOURCES = tests/test_capabilities.cpp tests_test_capabilities_LDADD = src/libzmq.la tests_test_xpub_nodrop_SOURCES = tests/test_xpub_nodrop.cpp -tests_test_xpub_nodrop_LDADD = src/libzmq.la +tests_test_xpub_nodrop_LDADD = src/libzmq.la ${UNITY_LIBS} +tests_test_xpub_nodrop_CPPFLAGS = ${UNITY_CPPFLAGS} tests_test_xpub_manual_SOURCES = tests/test_xpub_manual.cpp tests_test_xpub_manual_LDADD = src/libzmq.la @@ -659,7 +661,8 @@ tests_test_stream_exceeds_buffer_SOURCES = tests/test_stream_exceeds_buffer.cpp tests_test_stream_exceeds_buffer_LDADD = src/libzmq.la tests_test_pub_invert_matching_SOURCES = tests/test_pub_invert_matching.cpp -tests_test_pub_invert_matching_LDADD = src/libzmq.la +tests_test_pub_invert_matching_LDADD = src/libzmq.la ${UNITY_LIBS} +tests_test_pub_invert_matching_CPPFLAGS = ${UNITY_CPPFLAGS} tests_test_bind_after_connect_tcp_SOURCES = tests/test_bind_after_connect_tcp.cpp tests_test_bind_after_connect_tcp_LDADD = src/libzmq.la ${UNITY_LIBS} diff --git a/src/blob.hpp b/src/blob.hpp index bdd2ec2b..27a4b04c 100644 --- a/src/blob.hpp +++ b/src/blob.hpp @@ -125,6 +125,7 @@ struct blob_t { clear (); data_ = static_cast (malloc (other.size_)); + alloc_assert (data_); size_ = other.size_; owned_ = true; memcpy (data_, other.data_, size_); @@ -135,6 +136,7 @@ struct blob_t { clear (); data_ = static_cast (malloc (size)); + alloc_assert (data_); size_ = size; owned_ = true; memcpy (data_, data, size_); diff --git a/src/client.hpp b/src/client.hpp index 31239e31..55922c9b 100644 --- a/src/client.hpp +++ b/src/client.hpp @@ -31,7 +31,6 @@ #define __ZMQ_CLIENT_HPP_INCLUDED__ #include "socket_base.hpp" -#include "session_base.hpp" #include "fq.hpp" #include "lb.hpp" @@ -41,7 +40,6 @@ class ctx_t; class msg_t; class pipe_t; class io_thread_t; -class socket_base_t; class client_t : public socket_base_t { diff --git a/src/clock.cpp b/src/clock.cpp index dadf9e57..bd245438 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -57,11 +57,6 @@ #endif #if defined ZMQ_HAVE_OSX -#include -#include -#include -#include - int alt_clock_gettime (int clock_id, timespec *ts) { clock_serv_t cclock; diff --git a/src/clock.hpp b/src/clock.hpp index 3cef6538..b3f2eb55 100644 --- a/src/clock.hpp +++ b/src/clock.hpp @@ -33,17 +33,19 @@ #include "stdint.hpp" #if defined ZMQ_HAVE_OSX -#include -#include -#include -#include -int alt_clock_gettime (int clock_id, timespec *ts); +// TODO this is not required in this file, but condition_variable.hpp includes +// clock.hpp to get these definitions #ifndef CLOCK_REALTIME #define CLOCK_REALTIME 0 #endif #ifndef HAVE_CLOCK_GETTIME #define HAVE_CLOCK_GETTIME #endif + +#include +#include +#include +#include #endif namespace zmq diff --git a/src/condition_variable.hpp b/src/condition_variable.hpp index 8108777b..d65378fb 100644 --- a/src/condition_variable.hpp +++ b/src/condition_variable.hpp @@ -30,7 +30,6 @@ #ifndef __ZMQ_CONDITON_VARIABLE_HPP_INCLUDED__ #define __ZMQ_CONDITON_VARIABLE_HPP_INCLUDED__ -#include "clock.hpp" #include "err.hpp" #include "mutex.hpp" diff --git a/src/decoder.hpp b/src/decoder.hpp index 8cf663cd..46be55f7 100644 --- a/src/decoder.hpp +++ b/src/decoder.hpp @@ -37,7 +37,6 @@ #include "decoder_allocators.hpp" #include "err.hpp" #include "i_decoder.hpp" -#include "msg.hpp" #include "stdint.hpp" namespace zmq diff --git a/src/dish.hpp b/src/dish.hpp index fc6444cf..3af46c43 100644 --- a/src/dish.hpp +++ b/src/dish.hpp @@ -31,13 +31,12 @@ #define __ZMQ_DISH_HPP_INCLUDED__ #include -#include #include "socket_base.hpp" #include "session_base.hpp" #include "dist.hpp" #include "fq.hpp" -#include "trie.hpp" +#include "msg.hpp" namespace zmq { diff --git a/src/dist.hpp b/src/dist.hpp index 4f171ecc..f7d0245c 100644 --- a/src/dist.hpp +++ b/src/dist.hpp @@ -33,7 +33,6 @@ #include #include "array.hpp" -#include "pipe.hpp" namespace zmq { diff --git a/src/encoder.hpp b/src/encoder.hpp index b7703806..64320166 100644 --- a/src/encoder.hpp +++ b/src/encoder.hpp @@ -42,8 +42,8 @@ #include #include "err.hpp" -#include "msg.hpp" #include "i_encoder.hpp" +#include "msg.hpp" namespace zmq { diff --git a/src/fq.hpp b/src/fq.hpp index 6dd2f2ea..0386a862 100644 --- a/src/fq.hpp +++ b/src/fq.hpp @@ -32,11 +32,12 @@ #include "array.hpp" #include "blob.hpp" -#include "pipe.hpp" -#include "msg.hpp" namespace zmq { +class msg_t; +class pipe_t; + // Class manages a set of inbound pipes. On receive it performs fair // queueing so that senders gone berserk won't cause denial of // service for decent senders. diff --git a/src/gather.hpp b/src/gather.hpp index 0efed02c..9d05869a 100644 --- a/src/gather.hpp +++ b/src/gather.hpp @@ -31,7 +31,6 @@ #define __ZMQ_GATHER_HPP_INCLUDED__ #include "socket_base.hpp" -#include "session_base.hpp" #include "fq.hpp" namespace zmq @@ -39,7 +38,6 @@ namespace zmq class ctx_t; class pipe_t; class msg_t; -class io_thread_t; class gather_t : public socket_base_t { diff --git a/src/io_thread.hpp b/src/io_thread.hpp index 08fd67c5..5fcc4896 100644 --- a/src/io_thread.hpp +++ b/src/io_thread.hpp @@ -30,8 +30,6 @@ #ifndef __ZMQ_IO_THREAD_HPP_INCLUDED__ #define __ZMQ_IO_THREAD_HPP_INCLUDED__ -#include - #include "stdint.hpp" #include "object.hpp" #include "poller.hpp" diff --git a/src/lb.hpp b/src/lb.hpp index ba5e0bc7..c18399b5 100644 --- a/src/lb.hpp +++ b/src/lb.hpp @@ -31,10 +31,12 @@ #define __ZMQ_LB_HPP_INCLUDED__ #include "array.hpp" -#include "pipe.hpp" namespace zmq { +class msg_t; +class pipe_t; + // This class manages a set of outbound pipes. On send it load balances // messages fairly among the pipes. diff --git a/src/mechanism_base.hpp b/src/mechanism_base.hpp index a0eafdab..dfcd4fb9 100644 --- a/src/mechanism_base.hpp +++ b/src/mechanism_base.hpp @@ -34,6 +34,8 @@ namespace zmq { +class msg_t; + class mechanism_base_t : public mechanism_t { protected: diff --git a/src/norm_engine.hpp b/src/norm_engine.hpp index c3ce9296..5b241038 100644 --- a/src/norm_engine.hpp +++ b/src/norm_engine.hpp @@ -15,6 +15,7 @@ namespace zmq { class io_thread_t; +class msg_t; class session_base_t; class norm_engine_t : public io_object_t, public i_engine diff --git a/src/null_mechanism.cpp b/src/null_mechanism.cpp index 70fa958b..59367061 100644 --- a/src/null_mechanism.cpp +++ b/src/null_mechanism.cpp @@ -36,7 +36,6 @@ #include "err.hpp" #include "msg.hpp" #include "session_base.hpp" -#include "wire.hpp" #include "null_mechanism.hpp" zmq::null_mechanism_t::null_mechanism_t (session_base_t *session_, diff --git a/src/options.cpp b/src/options.cpp index 5628fb60..036b382d 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -29,6 +29,7 @@ #include "precompiled.hpp" #include +#include #include "options.hpp" #include "err.hpp" diff --git a/src/options.hpp b/src/options.hpp index e4a96ca2..dd0a6823 100644 --- a/src/options.hpp +++ b/src/options.hpp @@ -32,7 +32,6 @@ #include #include -#include #include #include "atomic_ptr.hpp" @@ -41,6 +40,7 @@ #include "tcp_address.hpp" #if defined ZMQ_HAVE_SO_PEERCRED || defined ZMQ_HAVE_LOCAL_PEERCRED +#include #include #endif #ifdef ZMQ_HAVE_LOCAL_PEERCRED diff --git a/src/own.hpp b/src/own.hpp index 8c2732fc..82bcf297 100644 --- a/src/own.hpp +++ b/src/own.hpp @@ -31,7 +31,6 @@ #define __ZMQ_OWN_HPP_INCLUDED__ #include -#include #include "object.hpp" #include "options.hpp" diff --git a/src/pipe.hpp b/src/pipe.hpp index 63f1b7db..9c9d9192 100644 --- a/src/pipe.hpp +++ b/src/pipe.hpp @@ -30,7 +30,6 @@ #ifndef __ZMQ_PIPE_HPP_INCLUDED__ #define __ZMQ_PIPE_HPP_INCLUDED__ -#include "msg.hpp" #include "ypipe_base.hpp" #include "config.hpp" #include "object.hpp" @@ -40,7 +39,7 @@ namespace zmq { -class object_t; +class msg_t; class pipe_t; // Create a pipepair for bi-directional transfer of messages. diff --git a/src/plain_server.hpp b/src/plain_server.hpp index c9352ab6..ba335e4d 100644 --- a/src/plain_server.hpp +++ b/src/plain_server.hpp @@ -30,7 +30,6 @@ #ifndef __ZMQ_PLAIN_SERVER_HPP_INCLUDED__ #define __ZMQ_PLAIN_SERVER_HPP_INCLUDED__ -#include "mechanism.hpp" #include "options.hpp" #include "zap_client.hpp" diff --git a/src/proxy.cpp b/src/proxy.cpp index 3e30e4d1..abf2615a 100644 --- a/src/proxy.cpp +++ b/src/proxy.cpp @@ -33,6 +33,7 @@ #include "poller.hpp" #include "proxy.hpp" #include "likely.hpp" +#include "msg.hpp" #if defined ZMQ_POLL_BASED_ON_POLL && !defined ZMQ_HAVE_WINDOWS \ && !defined ZMQ_HAVE_AIX diff --git a/src/radio.hpp b/src/radio.hpp index da8a4de8..c311e128 100644 --- a/src/radio.hpp +++ b/src/radio.hpp @@ -36,14 +36,12 @@ #include "socket_base.hpp" #include "session_base.hpp" -#include "mtrie.hpp" -#include "array.hpp" #include "dist.hpp" +#include "msg.hpp" namespace zmq { class ctx_t; -class msg_t; class pipe_t; class io_thread_t; diff --git a/src/raw_decoder.hpp b/src/raw_decoder.hpp index 81759b22..4cd0b1b3 100644 --- a/src/raw_decoder.hpp +++ b/src/raw_decoder.hpp @@ -30,7 +30,6 @@ #ifndef __ZMQ_RAW_DECODER_HPP_INCLUDED__ #define __ZMQ_RAW_DECODER_HPP_INCLUDED__ -#include "err.hpp" #include "msg.hpp" #include "i_decoder.hpp" #include "stdint.hpp" diff --git a/src/raw_encoder.cpp b/src/raw_encoder.cpp index 2c0c58c0..fa510963 100644 --- a/src/raw_encoder.cpp +++ b/src/raw_encoder.cpp @@ -30,8 +30,7 @@ #include "precompiled.hpp" #include "encoder.hpp" #include "raw_encoder.hpp" -#include "likely.hpp" -#include "wire.hpp" +#include "msg.hpp" zmq::raw_encoder_t::raw_encoder_t (size_t bufsize_) : encoder_base_t (bufsize_) diff --git a/src/raw_encoder.hpp b/src/raw_encoder.hpp index 8606ea61..5467a540 100644 --- a/src/raw_encoder.hpp +++ b/src/raw_encoder.hpp @@ -33,11 +33,8 @@ #include #include #include -#include -#include "err.hpp" -#include "msg.hpp" -#include "i_encoder.hpp" +#include "encoder.hpp" namespace zmq { diff --git a/src/select.hpp b/src/select.hpp index 7093c3d4..e27dc2d9 100644 --- a/src/select.hpp +++ b/src/select.hpp @@ -48,7 +48,6 @@ #include "ctx.hpp" #include "fd.hpp" -#include "thread.hpp" #include "poller_base.hpp" namespace zmq diff --git a/src/server.hpp b/src/server.hpp index c4125de9..c0796a68 100644 --- a/src/server.hpp +++ b/src/server.hpp @@ -36,12 +36,12 @@ #include "session_base.hpp" #include "stdint.hpp" #include "blob.hpp" -#include "msg.hpp" #include "fq.hpp" namespace zmq { class ctx_t; +class msg_t; class pipe_t; // TODO: This class uses O(n) scheduling. Rewrite it to use O(1) algorithm. diff --git a/src/session_base.hpp b/src/session_base.hpp index ae9f3a71..586fa261 100644 --- a/src/session_base.hpp +++ b/src/session_base.hpp @@ -30,7 +30,6 @@ #ifndef __ZMQ_SESSION_BASE_HPP_INCLUDED__ #define __ZMQ_SESSION_BASE_HPP_INCLUDED__ -#include #include #include "own.hpp" @@ -41,9 +40,7 @@ namespace zmq { -class pipe_t; class io_thread_t; -class socket_base_t; struct i_engine; struct address_t; diff --git a/src/socket_base.hpp b/src/socket_base.hpp index 5655819c..296b49f6 100644 --- a/src/socket_base.hpp +++ b/src/socket_base.hpp @@ -39,10 +39,8 @@ #include "blob.hpp" #include "stdint.hpp" #include "poller.hpp" -#include "atomic_counter.hpp" #include "i_poll_events.hpp" #include "i_mailbox.hpp" -#include "stdint.hpp" #include "clock.hpp" #include "pipe.hpp" diff --git a/src/socket_poller.hpp b/src/socket_poller.hpp index eb79a7ea..4e508e5c 100644 --- a/src/socket_poller.hpp +++ b/src/socket_poller.hpp @@ -47,7 +47,6 @@ #endif #include -#include #include "socket_base.hpp" #include "signaler.hpp" diff --git a/src/socks.cpp b/src/socks.cpp index 3e71b264..6c56bc94 100644 --- a/src/socks.cpp +++ b/src/socks.cpp @@ -166,14 +166,14 @@ void zmq::socks_request_encoder_t::encode (const socks_request_t &req) const int rc = getaddrinfo (req.hostname.c_str (), NULL, &hints, &res); if (rc == 0 && res->ai_family == AF_INET) { - struct sockaddr_in *sockaddr_in = - reinterpret_cast (res->ai_addr); + const struct sockaddr_in *sockaddr_in = + reinterpret_cast (res->ai_addr); *ptr++ = 0x01; memcpy (ptr, &sockaddr_in->sin_addr, 4); ptr += 4; } else if (rc == 0 && res->ai_family == AF_INET6) { - struct sockaddr_in6 *sockaddr_in6 = - reinterpret_cast (res->ai_addr); + const struct sockaddr_in6 *sockaddr_in6 = + reinterpret_cast (res->ai_addr); *ptr++ = 0x04; memcpy (ptr, &sockaddr_in6->sin6_addr, 16); ptr += 16; diff --git a/src/stream_engine.cpp b/src/stream_engine.cpp index 028a59e3..ee045d9e 100644 --- a/src/stream_engine.cpp +++ b/src/stream_engine.cpp @@ -1110,12 +1110,14 @@ int zmq::stream_engine_t::process_heartbeat_message (msg_t *msg_) int zmq::stream_engine_t::process_command_message (msg_t *msg_) { - uint8_t cmd_name_size = *(static_cast (msg_->data ())); + const uint8_t cmd_name_size = + *(static_cast (msg_->data ())); // Malformed command if (msg_->size () < cmd_name_size + sizeof (cmd_name_size)) return -1; - uint8_t *cmd_name = (static_cast (msg_->data ())) + 1; + const uint8_t *cmd_name = + (static_cast (msg_->data ())) + 1; if (cmd_name_size == 4 && (memcmp (cmd_name, "PING", cmd_name_size) == 0 || memcmp (cmd_name, "PONG", cmd_name_size) == 0)) diff --git a/src/stream_engine.hpp b/src/stream_engine.hpp index 2544f6c1..1ab9c039 100644 --- a/src/stream_engine.hpp +++ b/src/stream_engine.hpp @@ -40,6 +40,7 @@ #include "options.hpp" #include "socket_base.hpp" #include "metadata.hpp" +#include "msg.hpp" namespace zmq { @@ -51,7 +52,6 @@ enum }; class io_thread_t; -class msg_t; class session_base_t; class mechanism_t; diff --git a/src/tcp_connecter.cpp b/src/tcp_connecter.cpp index 833e379e..b983cc90 100644 --- a/src/tcp_connecter.cpp +++ b/src/tcp_connecter.cpp @@ -262,7 +262,7 @@ int zmq::tcp_connecter_t::open () return -1; } zmq_assert (addr->resolved.tcp_addr != NULL); - tcp_address_t *const tcp_addr = addr->resolved.tcp_addr; + const tcp_address_t *const tcp_addr = addr->resolved.tcp_addr; // Create the socket. s = open_socket (tcp_addr->family (), SOCK_STREAM, IPPROTO_TCP); diff --git a/src/udp_address.hpp b/src/udp_address.hpp index 1d240f1d..6c412e16 100644 --- a/src/udp_address.hpp +++ b/src/udp_address.hpp @@ -35,6 +35,8 @@ #include #endif +#include + #include "ip_resolver.hpp" namespace zmq diff --git a/src/udp_engine.cpp b/src/udp_engine.cpp index 53e9a653..41e96138 100644 --- a/src/udp_engine.cpp +++ b/src/udp_engine.cpp @@ -40,9 +40,9 @@ along with this program. If not, see . #endif #endif +#include "udp_address.hpp" #include "udp_engine.hpp" #include "session_base.hpp" -#include "v2_protocol.hpp" #include "err.hpp" #include "ip.hpp" @@ -285,14 +285,15 @@ void zmq::udp_engine_t::terminate () void zmq::udp_engine_t::sockaddr_to_msg (zmq::msg_t *msg, sockaddr_in *addr) { - char *name = inet_ntoa (addr->sin_addr); + const char *const name = inet_ntoa (addr->sin_addr); char port[6]; sprintf (port, "%d", static_cast (ntohs (addr->sin_port))); - int size = static_cast (strlen (name)) - + static_cast (strlen (port)) + 1 + 1; // Colon + NULL - int rc = msg->init_size (size); + const int size = static_cast (strlen (name)) + + static_cast (strlen (port)) + 1 + + 1; // Colon + NULL + const int rc = msg->init_size (size); errno_assert (rc == 0); msg->set_flags (msg_t::more); char *address = static_cast (msg->data ()); @@ -472,7 +473,8 @@ void zmq::udp_engine_t::in_event () body_size = nbytes; body_offset = 0; } else { - char *group_buffer = reinterpret_cast (in_buffer) + 1; + const char *group_buffer = + reinterpret_cast (in_buffer) + 1; int group_size = in_buffer[0]; rc = msg.init_size (group_size); diff --git a/src/udp_engine.hpp b/src/udp_engine.hpp index 1a02c524..02e39886 100644 --- a/src/udp_engine.hpp +++ b/src/udp_engine.hpp @@ -5,7 +5,6 @@ #include "io_object.hpp" #include "i_engine.hpp" #include "address.hpp" -#include "udp_address.hpp" #include "msg.hpp" #define MAX_UDP_MSG 8192 diff --git a/src/v1_encoder.cpp b/src/v1_encoder.cpp index e9ce9696..672071fa 100644 --- a/src/v1_encoder.cpp +++ b/src/v1_encoder.cpp @@ -30,7 +30,7 @@ #include "precompiled.hpp" #include "encoder.hpp" #include "v1_encoder.hpp" -#include "likely.hpp" +#include "msg.hpp" #include "wire.hpp" zmq::v1_encoder_t::v1_encoder_t (size_t bufsize_) : diff --git a/src/v2_encoder.cpp b/src/v2_encoder.cpp index 63362301..8efc4c5b 100644 --- a/src/v2_encoder.cpp +++ b/src/v2_encoder.cpp @@ -30,6 +30,7 @@ #include "precompiled.hpp" #include "v2_protocol.hpp" #include "v2_encoder.hpp" +#include "msg.hpp" #include "likely.hpp" #include "wire.hpp" diff --git a/src/xpub.cpp b/src/xpub.cpp index 717ddbfe..75144007 100644 --- a/src/xpub.cpp +++ b/src/xpub.cpp @@ -89,7 +89,8 @@ void zmq::xpub_t::xread_activated (pipe_t *pipe_) msg_t sub; while (pipe_->read (&sub)) { // Apply the subscription to the trie - unsigned char *const data = static_cast (sub.data ()); + const unsigned char *const data = + static_cast (sub.data ()); const size_t size = sub.size (); metadata_t *metadata = sub.metadata (); if (size > 0 && (*data == 0 || *data == 1)) { diff --git a/src/xpub.hpp b/src/xpub.hpp index c3f0d6cc..c552732e 100644 --- a/src/xpub.hpp +++ b/src/xpub.hpp @@ -31,12 +31,10 @@ #define __ZMQ_XPUB_HPP_INCLUDED__ #include -#include #include "socket_base.hpp" #include "session_base.hpp" #include "mtrie.hpp" -#include "array.hpp" #include "dist.hpp" namespace zmq diff --git a/src/zap_client.cpp b/src/zap_client.cpp index 38289fba..0c54c39f 100644 --- a/src/zap_client.cpp +++ b/src/zap_client.cpp @@ -186,7 +186,7 @@ int zap_client_t::receive_and_process_zap_reply () } // Status code frame, only 200, 300, 400 and 500 are valid status codes - char *status_code_data = static_cast (msg[3].data ()); + const char *status_code_data = static_cast (msg[3].data ()); if (msg[3].size () != 3 || status_code_data[0] < '2' || status_code_data[0] > '5' || status_code_data[1] != '0' || status_code_data[2] != '0') { diff --git a/src/zmq.cpp b/src/zmq.cpp index 5fe58342..d059e0f2 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -545,7 +545,7 @@ int zmq_recviov (void *s_, iovec *a_, size_t *count_, int flags_) memcpy (a_[i].iov_base, static_cast (zmq_msg_data (&msg)), a_[i].iov_len); // Assume zmq_socket ZMQ_RVCMORE is properly set. - zmq::msg_t *p_msg = reinterpret_cast (&msg); + const zmq::msg_t *p_msg = reinterpret_cast (&msg); recvmore = p_msg->flags () & zmq::msg_t::more; rc = zmq_msg_close (&msg); errno_assert (rc == 0); @@ -678,7 +678,8 @@ const char *zmq_msg_group (zmq_msg_t *msg_) const char *zmq_msg_gets (const zmq_msg_t *msg_, const char *property_) { - zmq::metadata_t *metadata = ((zmq::msg_t *) msg_)->metadata (); + const zmq::metadata_t *metadata = + reinterpret_cast (msg_)->metadata (); const char *value = NULL; if (metadata) value = metadata->get (std::string (property_)); @@ -1355,7 +1356,7 @@ int zmq_socket_get_peer_state (void *s_, const void *routing_id_, size_t routing_id_size_) { - zmq::socket_base_t *s = as_socket_base_t (s_); + const zmq::socket_base_t *const s = as_socket_base_t (s_); if (!s) return -1; diff --git a/tests/test_hwm_pubsub.cpp b/tests/test_hwm_pubsub.cpp index d34dc9cb..e4459c64 100644 --- a/tests/test_hwm_pubsub.cpp +++ b/tests/test_hwm_pubsub.cpp @@ -28,30 +28,35 @@ */ #include "testutil.hpp" +#include "testutil_unity.hpp" + +void setUp () +{ + setup_test_context (); +} + +void tearDown () +{ + teardown_test_context (); +} // const int MAX_SENDS = 10000; int test_defaults (int send_hwm, int msgCnt) { - void *ctx = zmq_ctx_new (); - assert (ctx); - int rc; - // Set up bind socket - void *pub_socket = zmq_socket (ctx, ZMQ_PUB); - assert (pub_socket); - rc = zmq_bind (pub_socket, "inproc://a"); - assert (rc == 0); + void *pub_socket = test_context_socket (ZMQ_PUB); + TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pub_socket, "inproc://a")); // Set up connect socket - void *sub_socket = zmq_socket (ctx, ZMQ_SUB); - assert (sub_socket); - rc = zmq_connect (sub_socket, "inproc://a"); - assert (rc == 0); + void *sub_socket = test_context_socket (ZMQ_SUB); + TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub_socket, "inproc://a")); //set a hwm on publisher - rc = zmq_setsockopt (pub_socket, ZMQ_SNDHWM, &send_hwm, sizeof (send_hwm)); - rc = zmq_setsockopt (sub_socket, ZMQ_SUBSCRIBE, 0, 0); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_setsockopt (pub_socket, ZMQ_SNDHWM, &send_hwm, sizeof (send_hwm))); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_setsockopt (sub_socket, ZMQ_SUBSCRIBE, 0, 0)); // Send until we block int send_count = 0; @@ -67,17 +72,11 @@ int test_defaults (int send_hwm, int msgCnt) ++recv_count; } - assert (send_hwm == recv_count); + TEST_ASSERT_EQUAL_INT (send_hwm, recv_count); // Clean up - rc = zmq_close (sub_socket); - assert (rc == 0); - - rc = zmq_close (pub_socket); - assert (rc == 0); - - rc = zmq_ctx_term (ctx); - assert (rc == 0); + test_context_socket_close (sub_socket); + test_context_socket_close (pub_socket); return recv_count; } @@ -96,89 +95,68 @@ int receive (void *socket) int test_blocking (int send_hwm, int msgCnt) { - void *ctx = zmq_ctx_new (); - assert (ctx); - int rc; - // Set up bind socket - void *pub_socket = zmq_socket (ctx, ZMQ_PUB); - assert (pub_socket); - rc = zmq_bind (pub_socket, "inproc://a"); - assert (rc == 0); + void *pub_socket = test_context_socket (ZMQ_PUB); + TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pub_socket, "inproc://a")); // Set up connect socket - void *sub_socket = zmq_socket (ctx, ZMQ_SUB); - assert (sub_socket); - rc = zmq_connect (sub_socket, "inproc://a"); - assert (rc == 0); + void *sub_socket = test_context_socket (ZMQ_SUB); + TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub_socket, "inproc://a")); //set a hwm on publisher - rc = zmq_setsockopt (pub_socket, ZMQ_SNDHWM, &send_hwm, sizeof (send_hwm)); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_setsockopt (pub_socket, ZMQ_SNDHWM, &send_hwm, sizeof (send_hwm))); int wait = 1; - rc = zmq_setsockopt (pub_socket, ZMQ_XPUB_NODROP, &wait, sizeof (wait)); - rc = zmq_setsockopt (sub_socket, ZMQ_SUBSCRIBE, 0, 0); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_setsockopt (pub_socket, ZMQ_XPUB_NODROP, &wait, sizeof (wait))); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_setsockopt (sub_socket, ZMQ_SUBSCRIBE, 0, 0)); // Send until we block int send_count = 0; int recv_count = 0; while (send_count < msgCnt) { - rc = zmq_send (pub_socket, NULL, 0, ZMQ_DONTWAIT); + const int rc = zmq_send (pub_socket, NULL, 0, ZMQ_DONTWAIT); if (rc == 0) { ++send_count; } else if (-1 == rc) { - assert (EAGAIN == errno); + TEST_ASSERT_EQUAL_INT (EAGAIN, errno); recv_count += receive (sub_socket); - assert (recv_count == send_count); + TEST_ASSERT_EQUAL_INT (send_count, recv_count); } } recv_count += receive (sub_socket); // Clean up - rc = zmq_close (sub_socket); - assert (rc == 0); - - rc = zmq_close (pub_socket); - assert (rc == 0); - - rc = zmq_ctx_term (ctx); - assert (rc == 0); + test_context_socket_close (sub_socket); + test_context_socket_close (pub_socket); return recv_count; } +// hwm should apply to the messages that have already been received // with hwm 11024: send 9999 msg, receive 9999, send 1100, receive 1100 void test_reset_hwm () { - int first_count = 9999; - int second_count = 1100; + const int first_count = 9999; + const int second_count = 1100; int hwm = 11024; - size_t len = MAX_SOCKET_STRING; char my_endpoint[MAX_SOCKET_STRING]; - void *ctx = zmq_ctx_new (); - assert (ctx); - int rc; - // Set up bind socket - void *pub_socket = zmq_socket (ctx, ZMQ_PUB); - assert (pub_socket); - rc = zmq_setsockopt (pub_socket, ZMQ_SNDHWM, &hwm, sizeof (hwm)); - assert (rc == 0); - rc = zmq_bind (pub_socket, "tcp://127.0.0.1:*"); - assert (rc == 0); - rc = zmq_getsockopt (pub_socket, ZMQ_LAST_ENDPOINT, my_endpoint, &len); - assert (rc == 0); + void *pub_socket = test_context_socket (ZMQ_PUB); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_setsockopt (pub_socket, ZMQ_SNDHWM, &hwm, sizeof (hwm))); + bind_loopback_ipv4 (pub_socket, my_endpoint, MAX_SOCKET_STRING); // Set up connect socket - void *sub_socket = zmq_socket (ctx, ZMQ_SUB); - assert (sub_socket); - rc = zmq_setsockopt (sub_socket, ZMQ_RCVHWM, &hwm, sizeof (hwm)); - assert (rc == 0); - rc = zmq_connect (sub_socket, my_endpoint); - assert (rc == 0); - rc = zmq_setsockopt (sub_socket, ZMQ_SUBSCRIBE, 0, 0); - assert (rc == 0); + void *sub_socket = test_context_socket (ZMQ_SUB); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_setsockopt (sub_socket, ZMQ_RCVHWM, &hwm, sizeof (hwm))); + TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub_socket, my_endpoint)); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_setsockopt (sub_socket, ZMQ_SUBSCRIBE, 0, 0)); msleep (SETTLE_TIME); @@ -187,7 +165,7 @@ void test_reset_hwm () while (send_count < first_count && zmq_send (pub_socket, NULL, 0, ZMQ_DONTWAIT) == 0) ++send_count; - assert (first_count == send_count); + TEST_ASSERT_EQUAL_INT (first_count, send_count); msleep (SETTLE_TIME); @@ -196,7 +174,7 @@ void test_reset_hwm () while (0 == zmq_recv (sub_socket, NULL, 0, ZMQ_DONTWAIT)) { ++recv_count; } - assert (first_count == recv_count); + TEST_ASSERT_EQUAL_INT (first_count, recv_count); msleep (SETTLE_TIME); @@ -205,7 +183,7 @@ void test_reset_hwm () while (send_count < second_count && zmq_send (pub_socket, NULL, 0, ZMQ_DONTWAIT) == 0) ++send_count; - assert (second_count == send_count); + TEST_ASSERT_EQUAL_INT (second_count, send_count); msleep (SETTLE_TIME); @@ -214,35 +192,32 @@ void test_reset_hwm () while (0 == zmq_recv (sub_socket, NULL, 0, ZMQ_DONTWAIT)) { ++recv_count; } - assert (second_count == recv_count); + TEST_ASSERT_EQUAL_INT (second_count, recv_count); // Clean up - rc = zmq_close (sub_socket); - assert (rc == 0); - - rc = zmq_close (pub_socket); - assert (rc == 0); - - rc = zmq_ctx_term (ctx); - assert (rc == 0); + test_context_socket_close (sub_socket); + test_context_socket_close (pub_socket); } -int main (void) +void test_defaults_1000 () +{ + // send 1000 msg on hwm 1000, receive 1000 + TEST_ASSERT_EQUAL_INT (1000, test_defaults (1000, 1000)); +} + +void test_blocking_2000 () +{ + // send 6000 msg on hwm 2000, drops above hwm, only receive hwm + TEST_ASSERT_EQUAL_INT (6000, test_blocking (2000, 6000)); +} + +int main () { setup_test_environment (); - int count; - - // send 1000 msg on hwm 1000, receive 1000 - count = test_defaults (1000, 1000); - assert (count == 1000); - - // send 6000 msg on hwm 2000, drops above hwm, only receive hwm - count = test_blocking (2000, 6000); - assert (count == 6000); - - // hwm should apply to the messages that have already been received - test_reset_hwm (); - - return 0; + UNITY_BEGIN (); + RUN_TEST (test_defaults_1000); + RUN_TEST (test_blocking_2000); + RUN_TEST (test_reset_hwm); + return UNITY_END (); } diff --git a/tests/test_pub_invert_matching.cpp b/tests/test_pub_invert_matching.cpp index 32e5dee4..1ebab883 100644 --- a/tests/test_pub_invert_matching.cpp +++ b/tests/test_pub_invert_matching.cpp @@ -28,109 +28,99 @@ */ #include "testutil.hpp" +#include "testutil_unity.hpp" -int main (void) +void setUp () { - setup_test_environment (); - void *ctx = zmq_ctx_new (); - assert (ctx); + setup_test_context (); +} +void tearDown () +{ + teardown_test_context (); +} + +void test () +{ // Create a publisher - void *pub = zmq_socket (ctx, ZMQ_PUB); - assert (pub); - int rc = zmq_bind (pub, "inproc://soname"); - assert (rc == 0); + void *pub = test_context_socket (ZMQ_PUB); + TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pub, "inproc://soname")); // Create two subscribers - void *sub1 = zmq_socket (ctx, ZMQ_SUB); - assert (sub1); - rc = zmq_connect (sub1, "inproc://soname"); - assert (rc == 0); + void *sub1 = test_context_socket (ZMQ_SUB); + TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub1, "inproc://soname")); - void *sub2 = zmq_socket (ctx, ZMQ_SUB); - assert (sub2); - rc = zmq_connect (sub2, "inproc://soname"); - assert (rc == 0); + void *sub2 = test_context_socket (ZMQ_SUB); + TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub2, "inproc://soname")); // Subscribe pub1 to one prefix // and pub2 to another prefix. const char PREFIX1[] = "prefix1"; const char PREFIX2[] = "p2"; - rc = zmq_setsockopt (sub1, ZMQ_SUBSCRIBE, PREFIX1, sizeof (PREFIX1)); - assert (rc == 0); - - rc = zmq_setsockopt (sub2, ZMQ_SUBSCRIBE, PREFIX2, sizeof (PREFIX2)); - assert (rc == 0); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_setsockopt (sub1, ZMQ_SUBSCRIBE, PREFIX1, strlen (PREFIX1))); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_setsockopt (sub2, ZMQ_SUBSCRIBE, PREFIX2, strlen (PREFIX2))); // Send a message with the first prefix - rc = zmq_send_const (pub, PREFIX1, sizeof (PREFIX1), 0); - assert (rc == sizeof (PREFIX1)); + send_string_expect_success (pub, PREFIX1, 0); + msleep (SETTLE_TIME); // sub1 should receive it, but not sub2 - rc = zmq_recv (sub1, NULL, 0, ZMQ_DONTWAIT); - assert (rc == sizeof (PREFIX1)); + recv_string_expect_success (sub1, PREFIX1, ZMQ_DONTWAIT); - rc = zmq_recv (sub2, NULL, 0, ZMQ_DONTWAIT); - assert (rc == -1); - assert (errno == EAGAIN); + TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_recv (sub2, NULL, 0, ZMQ_DONTWAIT)); // Send a message with the second prefix - rc = zmq_send_const (pub, PREFIX2, sizeof (PREFIX2), 0); - assert (rc == sizeof (PREFIX2)); + send_string_expect_success (pub, PREFIX2, 0); + msleep (SETTLE_TIME); // sub2 should receive it, but not sub1 - rc = zmq_recv (sub2, NULL, 0, ZMQ_DONTWAIT); - assert (rc == sizeof (PREFIX2)); + recv_string_expect_success (sub2, PREFIX2, ZMQ_DONTWAIT); - rc = zmq_recv (sub1, NULL, 0, ZMQ_DONTWAIT); - assert (rc == -1); - assert (errno == EAGAIN); + TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_recv (sub1, NULL, 0, ZMQ_DONTWAIT)); // Now invert the matching int invert = 1; - rc = zmq_setsockopt (pub, ZMQ_INVERT_MATCHING, &invert, sizeof (invert)); - assert (rc == 0); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_setsockopt (pub, ZMQ_INVERT_MATCHING, &invert, sizeof (invert))); // ... on both sides, otherwise the SUB socket will filter the messages out - rc = zmq_setsockopt (sub1, ZMQ_INVERT_MATCHING, &invert, sizeof (invert)); - rc = zmq_setsockopt (sub2, ZMQ_INVERT_MATCHING, &invert, sizeof (invert)); - assert (rc == 0); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_setsockopt (sub1, ZMQ_INVERT_MATCHING, &invert, sizeof (invert))); + TEST_ASSERT_SUCCESS_ERRNO ( + zmq_setsockopt (sub2, ZMQ_INVERT_MATCHING, &invert, sizeof (invert))); // Send a message with the first prefix - rc = zmq_send_const (pub, PREFIX1, sizeof (PREFIX1), 0); - assert (rc == sizeof (PREFIX1)); + send_string_expect_success (pub, PREFIX1, 0); + msleep (SETTLE_TIME); // sub2 should receive it, but not sub1 - rc = zmq_recv (sub2, NULL, 0, ZMQ_DONTWAIT); - assert (rc == sizeof (PREFIX1)); + recv_string_expect_success (sub2, PREFIX1, ZMQ_DONTWAIT); - rc = zmq_recv (sub1, NULL, 0, ZMQ_DONTWAIT); - assert (rc == -1); - assert (errno == EAGAIN); + TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_recv (sub1, NULL, 0, ZMQ_DONTWAIT)); // Send a message with the second prefix - rc = zmq_send_const (pub, PREFIX2, sizeof (PREFIX2), 0); - assert (rc == sizeof (PREFIX2)); + send_string_expect_success (pub, PREFIX2, 0); + msleep (SETTLE_TIME); // sub1 should receive it, but not sub2 - rc = zmq_recv (sub1, NULL, 0, ZMQ_DONTWAIT); - assert (rc == sizeof (PREFIX2)); - - rc = zmq_recv (sub2, NULL, 0, ZMQ_DONTWAIT); - assert (rc == -1); - assert (errno == EAGAIN); + recv_string_expect_success (sub1, PREFIX2, ZMQ_DONTWAIT); + TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_recv (sub2, NULL, 0, ZMQ_DONTWAIT)); // Clean up. - rc = zmq_close (pub); - assert (rc == 0); - rc = zmq_close (sub1); - assert (rc == 0); - rc = zmq_close (sub2); - assert (rc == 0); - rc = zmq_ctx_term (ctx); - assert (rc == 0); - - return 0; + test_context_socket_close (pub); + test_context_socket_close (sub1); + test_context_socket_close (sub2); +} + +int main () +{ + setup_test_environment (); + + UNITY_BEGIN (); + RUN_TEST (test); + return UNITY_END (); } diff --git a/tests/test_xpub_nodrop.cpp b/tests/test_xpub_nodrop.cpp index c56c620a..2a42a6e2 100644 --- a/tests/test_xpub_nodrop.cpp +++ b/tests/test_xpub_nodrop.cpp @@ -28,69 +28,68 @@ */ #include "testutil.hpp" +#include "testutil_unity.hpp" -int main (void) +void setUp () { - setup_test_environment (); - void *ctx = zmq_ctx_new (); - assert (ctx); + setup_test_context (); +} +void tearDown () +{ + teardown_test_context (); +} + +void test () +{ // Create a publisher - void *pub = zmq_socket (ctx, ZMQ_PUB); - assert (pub); + void *pub = test_context_socket (ZMQ_PUB); int hwm = 2000; - int rc = zmq_setsockopt (pub, ZMQ_SNDHWM, &hwm, 4); - assert (rc == 0); + TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (pub, ZMQ_SNDHWM, &hwm, 4)); - rc = zmq_bind (pub, "inproc://soname"); - assert (rc == 0); + TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pub, "inproc://soname")); // set pub socket options int wait = 1; - rc = zmq_setsockopt (pub, ZMQ_XPUB_NODROP, &wait, 4); - assert (rc == 0); + TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (pub, ZMQ_XPUB_NODROP, &wait, 4)); // Create a subscriber - void *sub = zmq_socket (ctx, ZMQ_SUB); - assert (sub); - rc = zmq_connect (sub, "inproc://soname"); - assert (rc == 0); + void *sub = test_context_socket (ZMQ_SUB); + TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub, "inproc://soname")); // Subscribe for all messages. - rc = zmq_setsockopt (sub, ZMQ_SUBSCRIBE, "", 0); - assert (rc == 0); + TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (sub, ZMQ_SUBSCRIBE, "", 0)); int hwmlimit = hwm - 1; int send_count = 0; // Send an empty message for (int i = 0; i < hwmlimit; i++) { - rc = zmq_send (pub, NULL, 0, 0); - assert (rc == 0); + TEST_ASSERT_SUCCESS_ERRNO (zmq_send (pub, NULL, 0, 0)); send_count++; } int recv_count = 0; do { // Receive the message in the subscriber - rc = zmq_recv (sub, NULL, 0, ZMQ_DONTWAIT); - if (rc == -1) - assert (errno == EAGAIN); - else { - assert (rc == 0); + int rc = zmq_recv (sub, NULL, 0, ZMQ_DONTWAIT); + if (rc == -1) { + TEST_ASSERT_EQUAL_INT (EAGAIN, errno); + break; + } else { + TEST_ASSERT_EQUAL_INT (0, rc); recv_count++; } - } while (rc == 0); + } while (true); - assert (send_count == recv_count); + TEST_ASSERT_EQUAL_INT (send_count, recv_count); // Now test real blocking behavior // Set a timeout, default is infinite int timeout = 0; - rc = zmq_setsockopt (pub, ZMQ_SNDTIMEO, &timeout, 4); - assert (rc == 0); + TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (pub, ZMQ_SNDTIMEO, &timeout, 4)); send_count = 0; recv_count = 0; @@ -99,19 +98,21 @@ int main (void) // Send an empty message until we get an error, which must be EAGAIN while (zmq_send (pub, "", 0, 0) == 0) send_count++; - assert (errno == EAGAIN); + TEST_ASSERT_EQUAL_INT (EAGAIN, errno); while (zmq_recv (sub, NULL, 0, ZMQ_DONTWAIT) == 0) recv_count++; - assert (send_count == recv_count); + TEST_ASSERT_EQUAL_INT (send_count, recv_count); // Clean up. - rc = zmq_close (pub); - assert (rc == 0); - rc = zmq_close (sub); - assert (rc == 0); - rc = zmq_ctx_term (ctx); - assert (rc == 0); - - return 0; + test_context_socket_close (pub); + test_context_socket_close (sub); +} + +int main () +{ + setup_test_environment (); + UNITY_BEGIN (); + RUN_TEST (test); + return UNITY_END (); }