mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-19 18:03:50 +00:00
Merge pull request #1541 from jemc/master
Problem: Source files contain mixed tabs and spaces.
This commit is contained in:
commit
ec98916e82
@ -517,8 +517,8 @@ ZMQ_EXPORT void zmq_threadclose (void* thread);
|
|||||||
|
|
||||||
#define ZMQ_UNUSED(object) (void)object
|
#define ZMQ_UNUSED(object) (void)object
|
||||||
#define LIBZMQ_DELETE(p_object) {\
|
#define LIBZMQ_DELETE(p_object) {\
|
||||||
delete p_object; \
|
delete p_object; \
|
||||||
p_object = 0; \
|
p_object = 0; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef ZMQ_EXPORT
|
#undef ZMQ_EXPORT
|
||||||
|
@ -45,10 +45,10 @@ namespace std
|
|||||||
{
|
{
|
||||||
typedef unsigned char char_type;
|
typedef unsigned char char_type;
|
||||||
// Unsigned as wint_t in unsigned.
|
// Unsigned as wint_t in unsigned.
|
||||||
typedef unsigned long int_type;
|
typedef unsigned long int_type;
|
||||||
typedef streampos pos_type;
|
typedef streampos pos_type;
|
||||||
typedef streamoff off_type;
|
typedef streamoff off_type;
|
||||||
typedef mbstate_t state_type;
|
typedef mbstate_t state_type;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
assign(char_type& __c1, const char_type& __c2)
|
assign(char_type& __c1, const char_type& __c2)
|
||||||
|
@ -149,16 +149,16 @@ uint64_t zmq::clock_t::now_us ()
|
|||||||
// Use POSIX clock_gettime function to get precise monotonic time.
|
// Use POSIX clock_gettime function to get precise monotonic time.
|
||||||
struct timespec tv;
|
struct timespec tv;
|
||||||
int rc = clock_gettime (CLOCK_MONOTONIC, &tv);
|
int rc = clock_gettime (CLOCK_MONOTONIC, &tv);
|
||||||
// Fix case where system has clock_gettime but CLOCK_MONOTONIC is not supported.
|
// Fix case where system has clock_gettime but CLOCK_MONOTONIC is not supported.
|
||||||
// This should be a configuration check, but I looked into it and writing an
|
// This should be a configuration check, but I looked into it and writing an
|
||||||
// AC_FUNC_CLOCK_MONOTONIC seems beyond my powers.
|
// AC_FUNC_CLOCK_MONOTONIC seems beyond my powers.
|
||||||
if( rc != 0) {
|
if( rc != 0) {
|
||||||
// Use POSIX gettimeofday function to get precise time.
|
// Use POSIX gettimeofday function to get precise time.
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int rc = gettimeofday (&tv, NULL);
|
int rc = gettimeofday (&tv, NULL);
|
||||||
errno_assert (rc == 0);
|
errno_assert (rc == 0);
|
||||||
return (tv.tv_sec * (uint64_t) 1000000 + tv.tv_usec);
|
return (tv.tv_sec * (uint64_t) 1000000 + tv.tv_usec);
|
||||||
}
|
}
|
||||||
return (tv.tv_sec * (uint64_t) 1000000 + tv.tv_nsec / 1000);
|
return (tv.tv_sec * (uint64_t) 1000000 + tv.tv_nsec / 1000);
|
||||||
|
|
||||||
#elif defined HAVE_GETHRTIME
|
#elif defined HAVE_GETHRTIME
|
||||||
|
@ -47,36 +47,36 @@
|
|||||||
namespace zmq
|
namespace zmq
|
||||||
{
|
{
|
||||||
|
|
||||||
class condition_variable_t
|
class condition_variable_t
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline condition_variable_t ()
|
inline condition_variable_t ()
|
||||||
{
|
{
|
||||||
zmq_assert(false);
|
zmq_assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ~condition_variable_t ()
|
inline ~condition_variable_t ()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int wait (mutex_t* mutex_, int timeout_ )
|
inline int wait (mutex_t* mutex_, int timeout_ )
|
||||||
{
|
{
|
||||||
zmq_assert(false);
|
zmq_assert(false);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void broadcast ()
|
inline void broadcast ()
|
||||||
{
|
{
|
||||||
zmq_assert(false);
|
zmq_assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Disable copy construction and assignment.
|
// Disable copy construction and assignment.
|
||||||
condition_variable_t (const condition_variable_t&);
|
condition_variable_t (const condition_variable_t&);
|
||||||
void operator = (const condition_variable_t&);
|
void operator = (const condition_variable_t&);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ namespace zmq
|
|||||||
zmq::socket_base_t *create_socket (int type_);
|
zmq::socket_base_t *create_socket (int type_);
|
||||||
void destroy_socket (zmq::socket_base_t *socket_);
|
void destroy_socket (zmq::socket_base_t *socket_);
|
||||||
|
|
||||||
// Start a new thread with proper scheduling parameters.
|
// Start a new thread with proper scheduling parameters.
|
||||||
void start_thread (thread_t &thread_, thread_fn *tfn_, void *arg_) const;
|
void start_thread (thread_t &thread_, thread_fn *tfn_, void *arg_) const;
|
||||||
|
|
||||||
// Send command to the destination thread.
|
// Send command to the destination thread.
|
||||||
@ -203,7 +203,7 @@ namespace zmq
|
|||||||
// Is IPv6 enabled on this context?
|
// Is IPv6 enabled on this context?
|
||||||
bool ipv6;
|
bool ipv6;
|
||||||
|
|
||||||
// Thread scheduling parameters.
|
// Thread scheduling parameters.
|
||||||
int thread_priority;
|
int thread_priority;
|
||||||
int thread_sched_policy;
|
int thread_sched_policy;
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ int zmq::gssapi_mechanism_base_t::decode_message (msg_t *msg_)
|
|||||||
|
|
||||||
const uint8_t flags = static_cast <char *> (plaintext.value)[0];
|
const uint8_t flags = static_cast <char *> (plaintext.value)[0];
|
||||||
if (flags & 0x01)
|
if (flags & 0x01)
|
||||||
msg_->set_flags (msg_t::more);
|
msg_->set_flags (msg_t::more);
|
||||||
if (flags & 0x02)
|
if (flags & 0x02)
|
||||||
msg_->set_flags (msg_t::command);
|
msg_->set_flags (msg_t::command);
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ int zmq::gssapi_server_t::process_handshake_command (msg_t *msg_)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (security_context_established) {
|
if (security_context_established) {
|
||||||
// Use ZAP protocol (RFC 27) to authenticate the user.
|
// Use ZAP protocol (RFC 27) to authenticate the user.
|
||||||
bool expecting_zap_reply = false;
|
bool expecting_zap_reply = false;
|
||||||
int rc = session->zap_connect ();
|
int rc = session->zap_connect ();
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
|
@ -85,8 +85,8 @@ namespace zmq
|
|||||||
void accept_context ();
|
void accept_context ();
|
||||||
int produce_next_token (msg_t *msg_);
|
int produce_next_token (msg_t *msg_);
|
||||||
int process_next_token (msg_t *msg_);
|
int process_next_token (msg_t *msg_);
|
||||||
void send_zap_request ();
|
void send_zap_request ();
|
||||||
int receive_and_process_zap_reply();
|
int receive_and_process_zap_reply();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -412,16 +412,16 @@ void zmq::mtrie_t::match (unsigned char *data_, size_t size_,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
// If there's one subnode (optimisation).
|
// If there's one subnode (optimisation).
|
||||||
if (current->count == 1) {
|
if (current->count == 1) {
|
||||||
if (data_ [0] != current->min)
|
if (data_ [0] != current->min)
|
||||||
break;
|
break;
|
||||||
current = current->next.node;
|
current = current->next.node;
|
||||||
data_++;
|
data_++;
|
||||||
size_--;
|
size_--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are multiple subnodes.
|
// If there are multiple subnodes.
|
||||||
if (data_ [0] < current->min || data_ [0] >=
|
if (data_ [0] < current->min || data_ [0] >=
|
||||||
current->min + current->count)
|
current->min + current->count)
|
||||||
break;
|
break;
|
||||||
|
@ -195,24 +195,24 @@ int zmq::pgm_socket_t::init (bool udp_encapsulation_, const char *network_)
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const int rcvbuf = (int) options.rcvbuf;
|
const int rcvbuf = (int) options.rcvbuf;
|
||||||
if (rcvbuf >= 0) {
|
if (rcvbuf >= 0) {
|
||||||
if (!pgm_setsockopt (sock, SOL_SOCKET, SO_RCVBUF, &rcvbuf,
|
if (!pgm_setsockopt (sock, SOL_SOCKET, SO_RCVBUF, &rcvbuf,
|
||||||
sizeof (rcvbuf)))
|
sizeof (rcvbuf)))
|
||||||
goto err_abort;
|
goto err_abort;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int sndbuf = (int) options.sndbuf;
|
const int sndbuf = (int) options.sndbuf;
|
||||||
if (sndbuf >= 0) {
|
if (sndbuf >= 0) {
|
||||||
if (!pgm_setsockopt (sock, SOL_SOCKET, SO_SNDBUF, &sndbuf,
|
if (!pgm_setsockopt (sock, SOL_SOCKET, SO_SNDBUF, &sndbuf,
|
||||||
sizeof (sndbuf)))
|
sizeof (sndbuf)))
|
||||||
goto err_abort;
|
goto err_abort;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int max_tpdu = (int) pgm_max_tpdu;
|
const int max_tpdu = (int) pgm_max_tpdu;
|
||||||
if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_MTU, &max_tpdu,
|
if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_MTU, &max_tpdu,
|
||||||
sizeof (max_tpdu)))
|
sizeof (max_tpdu)))
|
||||||
goto err_abort;
|
goto err_abort;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (receiver) {
|
if (receiver) {
|
||||||
@ -334,28 +334,28 @@ int zmq::pgm_socket_t::init (bool udp_encapsulation_, const char *network_)
|
|||||||
|
|
||||||
// Set IP level parameters.
|
// Set IP level parameters.
|
||||||
{
|
{
|
||||||
// Multicast loopback disabled by default
|
// Multicast loopback disabled by default
|
||||||
const int multicast_loop = 0;
|
const int multicast_loop = 0;
|
||||||
if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_MULTICAST_LOOP,
|
if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_MULTICAST_LOOP,
|
||||||
&multicast_loop, sizeof (multicast_loop)))
|
&multicast_loop, sizeof (multicast_loop)))
|
||||||
goto err_abort;
|
goto err_abort;
|
||||||
|
|
||||||
const int multicast_hops = options.multicast_hops;
|
const int multicast_hops = options.multicast_hops;
|
||||||
if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_MULTICAST_HOPS,
|
if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_MULTICAST_HOPS,
|
||||||
&multicast_hops, sizeof (multicast_hops)))
|
&multicast_hops, sizeof (multicast_hops)))
|
||||||
goto err_abort;
|
goto err_abort;
|
||||||
|
|
||||||
// Expedited Forwarding PHB for network elements, no ECN.
|
// Expedited Forwarding PHB for network elements, no ECN.
|
||||||
// Ignore return value due to varied runtime support.
|
// Ignore return value due to varied runtime support.
|
||||||
const int dscp = 0x2e << 2;
|
const int dscp = 0x2e << 2;
|
||||||
if (AF_INET6 != sa_family)
|
if (AF_INET6 != sa_family)
|
||||||
pgm_setsockopt (sock, IPPROTO_PGM, PGM_TOS,
|
pgm_setsockopt (sock, IPPROTO_PGM, PGM_TOS,
|
||||||
&dscp, sizeof (dscp));
|
&dscp, sizeof (dscp));
|
||||||
|
|
||||||
const int nonblocking = 1;
|
const int nonblocking = 1;
|
||||||
if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_NOBLOCK,
|
if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_NOBLOCK,
|
||||||
&nonblocking, sizeof (nonblocking)))
|
&nonblocking, sizeof (nonblocking)))
|
||||||
goto err_abort;
|
goto err_abort;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect PGM transport to start state machine.
|
// Connect PGM transport to start state machine.
|
||||||
|
@ -515,13 +515,13 @@ void zmq::pipe_t::set_hwms (int inhwm_, int outhwm_)
|
|||||||
|
|
||||||
// if either send or recv side has hwm <= 0 it means infinite so we should set hwms infinite
|
// if either send or recv side has hwm <= 0 it means infinite so we should set hwms infinite
|
||||||
if (inhwm_ <= 0 || inhwmboost <= 0)
|
if (inhwm_ <= 0 || inhwmboost <= 0)
|
||||||
in = 0;
|
in = 0;
|
||||||
|
|
||||||
if (outhwm_ <= 0 || outhwmboost <= 0)
|
if (outhwm_ <= 0 || outhwmboost <= 0)
|
||||||
out = 0;
|
out = 0;
|
||||||
|
|
||||||
lwm = compute_lwm(in);
|
lwm = compute_lwm(in);
|
||||||
hwm = out;
|
hwm = out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void zmq::pipe_t::set_hwms_boost(int inhwmboost_, int outhwmboost_)
|
void zmq::pipe_t::set_hwms_boost(int inhwmboost_, int outhwmboost_)
|
||||||
|
@ -316,12 +316,11 @@ int zmq::socket_base_t::setsockopt (int option_, const void *optval_,
|
|||||||
{
|
{
|
||||||
ENTER_MUTEX();
|
ENTER_MUTEX();
|
||||||
|
|
||||||
if (!options.is_valid(option_)) {
|
if (!options.is_valid(option_)) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
EXIT_MUTEX();
|
EXIT_MUTEX();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (unlikely (ctx_terminated)) {
|
if (unlikely (ctx_terminated)) {
|
||||||
errno = ETERM;
|
errno = ETERM;
|
||||||
@ -339,7 +338,7 @@ int zmq::socket_base_t::setsockopt (int option_, const void *optval_,
|
|||||||
// If the socket type doesn't support the option, pass it to
|
// If the socket type doesn't support the option, pass it to
|
||||||
// the generic option parser.
|
// the generic option parser.
|
||||||
rc = options.setsockopt (option_, optval_, optvallen_);
|
rc = options.setsockopt (option_, optval_, optvallen_);
|
||||||
update_pipe_options(option_);
|
update_pipe_options(option_);
|
||||||
|
|
||||||
EXIT_MUTEX();
|
EXIT_MUTEX();
|
||||||
return rc;
|
return rc;
|
||||||
@ -1308,13 +1307,13 @@ void zmq::socket_base_t::process_term (int linger_)
|
|||||||
|
|
||||||
void zmq::socket_base_t::update_pipe_options(int option_)
|
void zmq::socket_base_t::update_pipe_options(int option_)
|
||||||
{
|
{
|
||||||
if (option_ == ZMQ_SNDHWM || option_ == ZMQ_RCVHWM)
|
if (option_ == ZMQ_SNDHWM || option_ == ZMQ_RCVHWM)
|
||||||
{
|
{
|
||||||
for (pipes_t::size_type i = 0; i != pipes.size(); ++i)
|
for (pipes_t::size_type i = 0; i != pipes.size(); ++i)
|
||||||
{
|
{
|
||||||
pipes[i]->set_hwms(options.rcvhwm, options.sndhwm);
|
pipes[i]->set_hwms(options.rcvhwm, options.sndhwm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#if defined _WIN32_WCE
|
#if defined _WIN32_WCE
|
||||||
static DWORD thread_routine (LPVOID arg_)
|
static DWORD thread_routine (LPVOID arg_)
|
||||||
#else
|
#else
|
||||||
static unsigned int __stdcall thread_routine (void *arg_)
|
static unsigned int __stdcall thread_routine (void *arg_)
|
||||||
#endif
|
#endif
|
||||||
|
150
src/xpub.cpp
150
src/xpub.cpp
@ -40,17 +40,17 @@ zmq::xpub_t::xpub_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
|
|||||||
verbose_unsubs (false),
|
verbose_unsubs (false),
|
||||||
more (false),
|
more (false),
|
||||||
lossy (true),
|
lossy (true),
|
||||||
manual(false),
|
manual(false),
|
||||||
welcome_msg ()
|
welcome_msg ()
|
||||||
{
|
{
|
||||||
last_pipe = NULL;
|
last_pipe = NULL;
|
||||||
options.type = ZMQ_XPUB;
|
options.type = ZMQ_XPUB;
|
||||||
welcome_msg.init();
|
welcome_msg.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
zmq::xpub_t::~xpub_t ()
|
zmq::xpub_t::~xpub_t ()
|
||||||
{
|
{
|
||||||
welcome_msg.close();
|
welcome_msg.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void zmq::xpub_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_)
|
void zmq::xpub_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_)
|
||||||
@ -63,16 +63,16 @@ void zmq::xpub_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_)
|
|||||||
if (subscribe_to_all_)
|
if (subscribe_to_all_)
|
||||||
subscriptions.add (NULL, 0, pipe_);
|
subscriptions.add (NULL, 0, pipe_);
|
||||||
|
|
||||||
// if welcome message exist
|
// if welcome message exist
|
||||||
if (welcome_msg.size() > 0)
|
if (welcome_msg.size() > 0)
|
||||||
{
|
{
|
||||||
msg_t copy;
|
msg_t copy;
|
||||||
copy.init();
|
copy.init();
|
||||||
copy.copy(welcome_msg);
|
copy.copy(welcome_msg);
|
||||||
|
|
||||||
pipe_->write(©);
|
pipe_->write(©);
|
||||||
pipe_->flush();
|
pipe_->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
// The pipe is active when attached. Let's read the subscriptions from
|
// The pipe is active when attached. Let's read the subscriptions from
|
||||||
// it, if any.
|
// it, if any.
|
||||||
@ -88,31 +88,31 @@ void zmq::xpub_t::xread_activated (pipe_t *pipe_)
|
|||||||
unsigned char *const data = (unsigned char *) sub.data ();
|
unsigned char *const data = (unsigned char *) sub.data ();
|
||||||
const size_t size = sub.size ();
|
const size_t size = sub.size ();
|
||||||
if (size > 0 && (*data == 0 || *data == 1)) {
|
if (size > 0 && (*data == 0 || *data == 1)) {
|
||||||
if (manual)
|
if (manual)
|
||||||
{
|
{
|
||||||
last_pipe = pipe_;
|
last_pipe = pipe_;
|
||||||
pending_data.push_back(blob_t(data, size));
|
pending_data.push_back(blob_t(data, size));
|
||||||
pending_metadata.push_back(sub.metadata());
|
pending_metadata.push_back(sub.metadata());
|
||||||
pending_flags.push_back(0);
|
pending_flags.push_back(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool unique;
|
bool unique;
|
||||||
if (*data == 0)
|
if (*data == 0)
|
||||||
unique = subscriptions.rm(data + 1, size - 1, pipe_);
|
unique = subscriptions.rm(data + 1, size - 1, pipe_);
|
||||||
else
|
else
|
||||||
unique = subscriptions.add(data + 1, size - 1, pipe_);
|
unique = subscriptions.add(data + 1, size - 1, pipe_);
|
||||||
|
|
||||||
// If the (un)subscription is not a duplicate store it so that it can be
|
// If the (un)subscription is not a duplicate store it so that it can be
|
||||||
// passed to the user on next recv call unless verbose mode is enabled
|
// passed to the user on next recv call unless verbose mode is enabled
|
||||||
// which makes to pass always these messages.
|
// which makes to pass always these messages.
|
||||||
if (options.type == ZMQ_XPUB && (unique || (*data == 1 && verbose_subs) ||
|
if (options.type == ZMQ_XPUB && (unique || (*data == 1 && verbose_subs) ||
|
||||||
(*data == 0 && verbose_unsubs && verbose_subs))) {
|
(*data == 0 && verbose_unsubs && verbose_subs))) {
|
||||||
pending_data.push_back(blob_t(data, size));
|
pending_data.push_back(blob_t(data, size));
|
||||||
pending_metadata.push_back(sub.metadata());
|
pending_metadata.push_back(sub.metadata());
|
||||||
pending_flags.push_back(0);
|
pending_flags.push_back(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Process user message coming upstream from xsub socket
|
// Process user message coming upstream from xsub socket
|
||||||
@ -132,45 +132,45 @@ void zmq::xpub_t::xwrite_activated (pipe_t *pipe_)
|
|||||||
int zmq::xpub_t::xsetsockopt (int option_, const void *optval_,
|
int zmq::xpub_t::xsetsockopt (int option_, const void *optval_,
|
||||||
size_t optvallen_)
|
size_t optvallen_)
|
||||||
{
|
{
|
||||||
if (option_ == ZMQ_XPUB_VERBOSE || option_ == ZMQ_XPUB_VERBOSE_UNSUBSCRIBE ||
|
if (option_ == ZMQ_XPUB_VERBOSE || option_ == ZMQ_XPUB_VERBOSE_UNSUBSCRIBE ||
|
||||||
option_ == ZMQ_XPUB_NODROP || option_ == ZMQ_XPUB_MANUAL)
|
option_ == ZMQ_XPUB_NODROP || option_ == ZMQ_XPUB_MANUAL)
|
||||||
{
|
{
|
||||||
if (optvallen_ != sizeof(int) || *static_cast <const int*> (optval_) < 0) {
|
if (optvallen_ != sizeof(int) || *static_cast <const int*> (optval_) < 0) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (option_ == ZMQ_XPUB_VERBOSE)
|
if (option_ == ZMQ_XPUB_VERBOSE)
|
||||||
verbose_subs = (*static_cast <const int*> (optval_) != 0);
|
verbose_subs = (*static_cast <const int*> (optval_) != 0);
|
||||||
else
|
else
|
||||||
if (option_ == ZMQ_XPUB_VERBOSE_UNSUBSCRIBE)
|
if (option_ == ZMQ_XPUB_VERBOSE_UNSUBSCRIBE)
|
||||||
verbose_unsubs = (*static_cast <const int*> (optval_) != 0);
|
verbose_unsubs = (*static_cast <const int*> (optval_) != 0);
|
||||||
else
|
else
|
||||||
if (option_ == ZMQ_XPUB_NODROP)
|
if (option_ == ZMQ_XPUB_NODROP)
|
||||||
lossy = (*static_cast <const int*> (optval_) == 0);
|
lossy = (*static_cast <const int*> (optval_) == 0);
|
||||||
else
|
else
|
||||||
if (option_ == ZMQ_XPUB_MANUAL)
|
if (option_ == ZMQ_XPUB_MANUAL)
|
||||||
manual = (*static_cast <const int*> (optval_) != 0);
|
manual = (*static_cast <const int*> (optval_) != 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (option_ == ZMQ_SUBSCRIBE && manual && last_pipe != NULL)
|
if (option_ == ZMQ_SUBSCRIBE && manual && last_pipe != NULL)
|
||||||
subscriptions.add((unsigned char *)optval_, optvallen_, last_pipe);
|
subscriptions.add((unsigned char *)optval_, optvallen_, last_pipe);
|
||||||
else
|
else
|
||||||
if (option_ == ZMQ_UNSUBSCRIBE && manual && last_pipe != NULL)
|
if (option_ == ZMQ_UNSUBSCRIBE && manual && last_pipe != NULL)
|
||||||
subscriptions.rm((unsigned char *)optval_, optvallen_, last_pipe);
|
subscriptions.rm((unsigned char *)optval_, optvallen_, last_pipe);
|
||||||
else
|
else
|
||||||
if (option_ == ZMQ_XPUB_WELCOME_MSG) {
|
if (option_ == ZMQ_XPUB_WELCOME_MSG) {
|
||||||
welcome_msg.close();
|
welcome_msg.close();
|
||||||
|
|
||||||
if (optvallen_ > 0) {
|
if (optvallen_ > 0) {
|
||||||
welcome_msg.init_size(optvallen_);
|
welcome_msg.init_size(optvallen_);
|
||||||
|
|
||||||
unsigned char *data = (unsigned char*)welcome_msg.data();
|
unsigned char *data = (unsigned char*)welcome_msg.data();
|
||||||
memcpy(data, optval_, optvallen_);
|
memcpy(data, optval_, optvallen_);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
welcome_msg.init();
|
welcome_msg.init();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -245,10 +245,10 @@ int zmq::xpub_t::xrecv (msg_t *msg_)
|
|||||||
pending_data.front ().data (),
|
pending_data.front ().data (),
|
||||||
pending_data.front ().size ());
|
pending_data.front ().size ());
|
||||||
|
|
||||||
// set metadata only if there is some
|
// set metadata only if there is some
|
||||||
if (metadata_t* metadata = pending_metadata.front ()) {
|
if (metadata_t* metadata = pending_metadata.front ()) {
|
||||||
msg_->set_metadata (metadata);
|
msg_->set_metadata (metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
msg_->set_flags (pending_flags.front ());
|
msg_->set_flags (pending_flags.front ());
|
||||||
pending_data.pop_front ();
|
pending_data.pop_front ();
|
||||||
|
12
src/xpub.hpp
12
src/xpub.hpp
@ -96,14 +96,14 @@ namespace zmq
|
|||||||
// Drop messages if HWM reached, otherwise return with EAGAIN
|
// Drop messages if HWM reached, otherwise return with EAGAIN
|
||||||
bool lossy;
|
bool lossy;
|
||||||
|
|
||||||
// Subscriptions will not bed added automatically, only after calling set option with ZMQ_SUBSCRIBE or ZMQ_UNSUBSCRIBE
|
// Subscriptions will not bed added automatically, only after calling set option with ZMQ_SUBSCRIBE or ZMQ_UNSUBSCRIBE
|
||||||
bool manual;
|
bool manual;
|
||||||
|
|
||||||
// Last pipe send subscription message, only used if xpub is on manual
|
// Last pipe send subscription message, only used if xpub is on manual
|
||||||
pipe_t *last_pipe;
|
pipe_t *last_pipe;
|
||||||
|
|
||||||
// Welcome message to send to pipe when attached
|
// Welcome message to send to pipe when attached
|
||||||
msg_t welcome_msg;
|
msg_t welcome_msg;
|
||||||
|
|
||||||
// List of pending (un)subscriptions, ie. those that were already
|
// List of pending (un)subscriptions, ie. those that were already
|
||||||
// applied to the trie, but not yet received by the user.
|
// applied to the trie, but not yet received by the user.
|
||||||
|
@ -183,7 +183,7 @@ int main (void)
|
|||||||
{
|
{
|
||||||
setup_test_environment ();
|
setup_test_environment ();
|
||||||
|
|
||||||
test_stream_2_stream ();
|
test_stream_2_stream ();
|
||||||
test_router_2_router (false);
|
test_router_2_router (false);
|
||||||
test_router_2_router (true);
|
test_router_2_router (true);
|
||||||
|
|
||||||
|
@ -71,14 +71,14 @@ int main (void)
|
|||||||
zmq_recvmsg(rep, &msg, 0);
|
zmq_recvmsg(rep, &msg, 0);
|
||||||
assert(zmq_msg_size(&msg) == MSG_SIZE);
|
assert(zmq_msg_size(&msg) == MSG_SIZE);
|
||||||
|
|
||||||
// get the messages source file descriptor
|
// get the messages source file descriptor
|
||||||
int srcFd = zmq_msg_get(&msg, ZMQ_SRCFD);
|
int srcFd = zmq_msg_get(&msg, ZMQ_SRCFD);
|
||||||
assert(srcFd >= 0);
|
assert(srcFd >= 0);
|
||||||
|
|
||||||
rc = zmq_msg_close(&msg);
|
rc = zmq_msg_close(&msg);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
// get the remote endpoint
|
// get the remote endpoint
|
||||||
struct sockaddr_storage ss;
|
struct sockaddr_storage ss;
|
||||||
#ifdef ZMQ_HAVE_HPUX
|
#ifdef ZMQ_HAVE_HPUX
|
||||||
int addrlen = sizeof ss;
|
int addrlen = sizeof ss;
|
||||||
@ -92,7 +92,7 @@ int main (void)
|
|||||||
rc = getnameinfo ((struct sockaddr*) &ss, addrlen, host, sizeof host, NULL, 0, NI_NUMERICHOST);
|
rc = getnameinfo ((struct sockaddr*) &ss, addrlen, host, sizeof host, NULL, 0, NI_NUMERICHOST);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
// assert it is localhost which connected
|
// assert it is localhost which connected
|
||||||
assert (strcmp(host, "127.0.0.1") == 0);
|
assert (strcmp(host, "127.0.0.1") == 0);
|
||||||
|
|
||||||
rc = zmq_close (rep);
|
rc = zmq_close (rep);
|
||||||
@ -100,10 +100,10 @@ int main (void)
|
|||||||
rc = zmq_close (req);
|
rc = zmq_close (req);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
// sleep a bit for the socket to be freed
|
// sleep a bit for the socket to be freed
|
||||||
usleep(30000);
|
usleep(30000);
|
||||||
|
|
||||||
// getting name from closed socket will fail
|
// getting name from closed socket will fail
|
||||||
rc = getpeername (srcFd, (struct sockaddr*) &ss, &addrlen);
|
rc = getpeername (srcFd, (struct sockaddr*) &ss, &addrlen);
|
||||||
assert (rc == -1);
|
assert (rc == -1);
|
||||||
assert (errno == EBADF);
|
assert (errno == EBADF);
|
||||||
|
@ -165,18 +165,18 @@ int main(int, char**)
|
|||||||
// Grab the 1st frame (peer identity).
|
// Grab the 1st frame (peer identity).
|
||||||
zmq_msg_t peer_frame;
|
zmq_msg_t peer_frame;
|
||||||
rc = zmq_msg_init (&peer_frame);
|
rc = zmq_msg_init (&peer_frame);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
rc = zmq_msg_recv (&peer_frame, sockets [SERVER], 0);
|
rc = zmq_msg_recv (&peer_frame, sockets [SERVER], 0);
|
||||||
assert (rc != -1);
|
assert (rc != -1);
|
||||||
assert(zmq_msg_size (&peer_frame) > 0);
|
assert(zmq_msg_size (&peer_frame) > 0);
|
||||||
assert (has_more (sockets [SERVER]));
|
assert (has_more (sockets [SERVER]));
|
||||||
|
|
||||||
// Grab the 2nd frame (actual payload).
|
// Grab the 2nd frame (actual payload).
|
||||||
zmq_msg_t data_frame;
|
zmq_msg_t data_frame;
|
||||||
rc = zmq_msg_init (&data_frame);
|
rc = zmq_msg_init (&data_frame);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
rc = zmq_msg_recv (&data_frame, sockets [SERVER], 0);
|
rc = zmq_msg_recv (&data_frame, sockets [SERVER], 0);
|
||||||
assert (rc != -1);
|
assert (rc != -1);
|
||||||
|
|
||||||
// Make sure payload matches what we expect.
|
// Make sure payload matches what we expect.
|
||||||
const char * const data = (const char*)zmq_msg_data (&data_frame);
|
const char * const data = (const char*)zmq_msg_data (&data_frame);
|
||||||
@ -184,39 +184,39 @@ int main(int, char**)
|
|||||||
// 0-length frame is a disconnection notification. The server
|
// 0-length frame is a disconnection notification. The server
|
||||||
// should receive it as the last step in the dialogue.
|
// should receive it as the last step in the dialogue.
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
++step;
|
++step;
|
||||||
assert (step == steps);
|
assert (step == steps);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert ((size_t) size == strlen (dialog [step].text));
|
assert ((size_t) size == strlen (dialog [step].text));
|
||||||
int cmp = memcmp (dialog [step].text, data, size);
|
int cmp = memcmp (dialog [step].text, data, size);
|
||||||
assert (cmp == 0);
|
assert (cmp == 0);
|
||||||
|
|
||||||
++step;
|
++step;
|
||||||
|
|
||||||
assert (step < steps);
|
assert (step < steps);
|
||||||
|
|
||||||
// Prepare the response.
|
// Prepare the response.
|
||||||
rc = zmq_msg_close (&data_frame);
|
rc = zmq_msg_close (&data_frame);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
rc = zmq_msg_init_size (&data_frame,
|
rc = zmq_msg_init_size (&data_frame,
|
||||||
strlen (dialog [step].text));
|
strlen (dialog [step].text));
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
memcpy (zmq_msg_data (&data_frame), dialog [step].text,
|
memcpy (zmq_msg_data (&data_frame), dialog [step].text,
|
||||||
zmq_msg_size (&data_frame));
|
zmq_msg_size (&data_frame));
|
||||||
|
|
||||||
// Send the response.
|
// Send the response.
|
||||||
rc = zmq_msg_send (&peer_frame, sockets [SERVER], ZMQ_SNDMORE);
|
rc = zmq_msg_send (&peer_frame, sockets [SERVER], ZMQ_SNDMORE);
|
||||||
assert (rc != -1);
|
assert (rc != -1);
|
||||||
rc = zmq_msg_send (&data_frame, sockets [SERVER], ZMQ_SNDMORE);
|
rc = zmq_msg_send (&data_frame, sockets [SERVER], ZMQ_SNDMORE);
|
||||||
assert (rc != -1);
|
assert (rc != -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release resources.
|
// Release resources.
|
||||||
rc = zmq_msg_close (&peer_frame);
|
rc = zmq_msg_close (&peer_frame);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
rc = zmq_msg_close (&data_frame);
|
rc = zmq_msg_close (&data_frame);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for data received by the client.
|
// Check for data received by the client.
|
||||||
@ -226,24 +226,24 @@ int main(int, char**)
|
|||||||
// Grab the 1st frame (peer identity).
|
// Grab the 1st frame (peer identity).
|
||||||
zmq_msg_t peer_frame;
|
zmq_msg_t peer_frame;
|
||||||
rc = zmq_msg_init (&peer_frame);
|
rc = zmq_msg_init (&peer_frame);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
rc = zmq_msg_recv (&peer_frame, sockets [CLIENT], 0);
|
rc = zmq_msg_recv (&peer_frame, sockets [CLIENT], 0);
|
||||||
assert (rc != -1);
|
assert (rc != -1);
|
||||||
assert(zmq_msg_size (&peer_frame) > 0);
|
assert(zmq_msg_size (&peer_frame) > 0);
|
||||||
assert (has_more (sockets [CLIENT]));
|
assert (has_more (sockets [CLIENT]));
|
||||||
|
|
||||||
// Grab the 2nd frame (actual payload).
|
// Grab the 2nd frame (actual payload).
|
||||||
zmq_msg_t data_frame;
|
zmq_msg_t data_frame;
|
||||||
rc = zmq_msg_init (&data_frame);
|
rc = zmq_msg_init (&data_frame);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
rc = zmq_msg_recv (&data_frame, sockets [CLIENT], 0);
|
rc = zmq_msg_recv (&data_frame, sockets [CLIENT], 0);
|
||||||
assert (rc != -1);
|
assert (rc != -1);
|
||||||
assert(zmq_msg_size (&data_frame) > 0);
|
assert(zmq_msg_size (&data_frame) > 0);
|
||||||
|
|
||||||
// Make sure payload matches what we expect.
|
// Make sure payload matches what we expect.
|
||||||
const char * const data = (const char*)zmq_msg_data (&data_frame);
|
const char * const data = (const char*)zmq_msg_data (&data_frame);
|
||||||
const int size = zmq_msg_size (&data_frame);
|
const int size = zmq_msg_size (&data_frame);
|
||||||
assert ((size_t)size == strlen(dialog [step].text));
|
assert ((size_t)size == strlen(dialog [step].text));
|
||||||
int cmp = memcmp(dialog [step].text, data, size);
|
int cmp = memcmp(dialog [step].text, data, size);
|
||||||
assert (cmp == 0);
|
assert (cmp == 0);
|
||||||
|
|
||||||
@ -252,22 +252,22 @@ int main(int, char**)
|
|||||||
// Prepare the response (next line in the dialog).
|
// Prepare the response (next line in the dialog).
|
||||||
assert (step < steps);
|
assert (step < steps);
|
||||||
rc = zmq_msg_close (&data_frame);
|
rc = zmq_msg_close (&data_frame);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
rc = zmq_msg_init_size (&data_frame, strlen (dialog [step].text));
|
rc = zmq_msg_init_size (&data_frame, strlen (dialog [step].text));
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
memcpy (zmq_msg_data (&data_frame), dialog [step].text, zmq_msg_size (&data_frame));
|
memcpy (zmq_msg_data (&data_frame), dialog [step].text, zmq_msg_size (&data_frame));
|
||||||
|
|
||||||
// Send the response.
|
// Send the response.
|
||||||
rc = zmq_msg_send (&peer_frame, sockets [CLIENT], ZMQ_SNDMORE);
|
rc = zmq_msg_send (&peer_frame, sockets [CLIENT], ZMQ_SNDMORE);
|
||||||
assert (rc != -1);
|
assert (rc != -1);
|
||||||
rc = zmq_msg_send (&data_frame, sockets [CLIENT], ZMQ_SNDMORE);
|
rc = zmq_msg_send (&data_frame, sockets [CLIENT], ZMQ_SNDMORE);
|
||||||
assert (rc != -1);
|
assert (rc != -1);
|
||||||
|
|
||||||
// Release resources.
|
// Release resources.
|
||||||
rc = zmq_msg_close (&peer_frame);
|
rc = zmq_msg_close (&peer_frame);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
rc = zmq_msg_close (&data_frame);
|
rc = zmq_msg_close (&data_frame);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert (step == steps);
|
assert (step == steps);
|
||||||
|
@ -56,42 +56,42 @@ int main (void)
|
|||||||
rc = zmq_connect (client2, "tcp://127.0.0.1:5560");
|
rc = zmq_connect (client2, "tcp://127.0.0.1:5560");
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
void* t1 = zmq_threadstart(worker1, client2);
|
void* t1 = zmq_threadstart(worker1, client2);
|
||||||
void* t2 = zmq_threadstart(worker2, client2);
|
void* t2 = zmq_threadstart(worker2, client2);
|
||||||
|
|
||||||
char data[1];
|
char data[1];
|
||||||
data[0] = 0;
|
data[0] = 0;
|
||||||
|
|
||||||
for (int i=0; i < 10; i++) {
|
for (int i=0; i < 10; i++) {
|
||||||
rc = zmq_send_const(client, data, 1, 0);
|
rc = zmq_send_const(client, data, 1, 0);
|
||||||
assert (rc == 1);
|
assert (rc == 1);
|
||||||
|
|
||||||
rc = zmq_send_const(client, data, 1, 0);
|
rc = zmq_send_const(client, data, 1, 0);
|
||||||
assert(rc == 1);
|
assert(rc == 1);
|
||||||
|
|
||||||
char a, b;
|
char a, b;
|
||||||
|
|
||||||
rc = zmq_recv(client, &a, 1, 0);
|
rc = zmq_recv(client, &a, 1, 0);
|
||||||
assert(rc == 1);
|
assert(rc == 1);
|
||||||
|
|
||||||
rc = zmq_recv(client, &b, 1, 0);
|
rc = zmq_recv(client, &b, 1, 0);
|
||||||
assert(rc == 1);
|
assert(rc == 1);
|
||||||
|
|
||||||
// make sure they came from different threads
|
// make sure they came from different threads
|
||||||
assert((a == 1 && b == 2) || (a == 2 && b == 1));
|
assert((a == 1 && b == 2) || (a == 2 && b == 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// make the thread exit
|
// make the thread exit
|
||||||
data[0] = 1;
|
data[0] = 1;
|
||||||
|
|
||||||
rc = zmq_send_const(client, data, 1, 0);
|
rc = zmq_send_const(client, data, 1, 0);
|
||||||
assert (rc == 1);
|
assert (rc == 1);
|
||||||
|
|
||||||
rc = zmq_send_const(client, data, 1, 0);
|
rc = zmq_send_const(client, data, 1, 0);
|
||||||
assert(rc == 1);
|
assert(rc == 1);
|
||||||
|
|
||||||
zmq_threadclose(t1);
|
zmq_threadclose(t1);
|
||||||
zmq_threadclose(t2);
|
zmq_threadclose(t2);
|
||||||
|
|
||||||
rc = zmq_close (client2);
|
rc = zmq_close (client2);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
@ -107,52 +107,52 @@ int main (void)
|
|||||||
|
|
||||||
void worker1(void* s)
|
void worker1(void* s)
|
||||||
{
|
{
|
||||||
const char worker_id = 1;
|
const char worker_id = 1;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
int rc = zmq_recv(s, &c,1, 0);
|
int rc = zmq_recv(s, &c,1, 0);
|
||||||
assert(rc == 1);
|
assert(rc == 1);
|
||||||
|
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
{
|
{
|
||||||
msleep(100);
|
msleep(100);
|
||||||
rc = zmq_send_const(s,&worker_id, 1, 0);
|
rc = zmq_send_const(s,&worker_id, 1, 0);
|
||||||
assert(rc == 1);
|
assert(rc == 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// we got exit request
|
// we got exit request
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void worker2(void* s)
|
void worker2(void* s)
|
||||||
{
|
{
|
||||||
const char worker_id = 2;
|
const char worker_id = 2;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
int rc = zmq_recv(s, &c,1, 0);
|
int rc = zmq_recv(s, &c,1, 0);
|
||||||
assert(rc == 1);
|
assert(rc == 1);
|
||||||
|
|
||||||
assert(c == 1 || c == 0);
|
assert(c == 1 || c == 0);
|
||||||
|
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
{
|
{
|
||||||
msleep(100);
|
msleep(100);
|
||||||
rc = zmq_send_const(s,&worker_id, 1, 0);
|
rc = zmq_send_const(s,&worker_id, 1, 0);
|
||||||
assert(rc == 1);
|
assert(rc == 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// we got exit request
|
// we got exit request
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ int main (void)
|
|||||||
|
|
||||||
// set pub socket options
|
// set pub socket options
|
||||||
int manual = 1;
|
int manual = 1;
|
||||||
rc = zmq_setsockopt(pub, ZMQ_XPUB_MANUAL, &manual, 4);
|
rc = zmq_setsockopt(pub, ZMQ_XPUB_MANUAL, &manual, 4);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
// Create a subscriber
|
// Create a subscriber
|
||||||
@ -53,32 +53,32 @@ int main (void)
|
|||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
// Subscribe for A
|
// Subscribe for A
|
||||||
char subscription[2] = { 1, 'A'};
|
char subscription[2] = { 1, 'A'};
|
||||||
rc = zmq_send_const(sub, subscription, 2, 0);
|
rc = zmq_send_const(sub, subscription, 2, 0);
|
||||||
assert (rc == 2);
|
assert (rc == 2);
|
||||||
|
|
||||||
char buffer[2];
|
char buffer[2];
|
||||||
|
|
||||||
// Receive subscriptions from subscriber
|
// Receive subscriptions from subscriber
|
||||||
rc = zmq_recv(pub, buffer, 2, 0);
|
rc = zmq_recv(pub, buffer, 2, 0);
|
||||||
assert(rc == 2);
|
assert(rc == 2);
|
||||||
assert(buffer[0] == 1);
|
assert(buffer[0] == 1);
|
||||||
assert(buffer[1] == 'A');
|
assert(buffer[1] == 'A');
|
||||||
|
|
||||||
// Subscribe socket for B instead
|
// Subscribe socket for B instead
|
||||||
rc = zmq_setsockopt(pub, ZMQ_SUBSCRIBE, "B", 1);
|
rc = zmq_setsockopt(pub, ZMQ_SUBSCRIBE, "B", 1);
|
||||||
assert(rc == 0);
|
assert(rc == 0);
|
||||||
|
|
||||||
// Sending A message and B Message
|
// Sending A message and B Message
|
||||||
rc = zmq_send_const(pub, "A", 1, 0);
|
rc = zmq_send_const(pub, "A", 1, 0);
|
||||||
assert(rc == 1);
|
assert(rc == 1);
|
||||||
|
|
||||||
rc = zmq_send_const(pub, "B", 1, 0);
|
rc = zmq_send_const(pub, "B", 1, 0);
|
||||||
assert(rc == 1);
|
assert(rc == 1);
|
||||||
|
|
||||||
rc = zmq_recv(sub, buffer, 1, ZMQ_DONTWAIT);
|
rc = zmq_recv(sub, buffer, 1, ZMQ_DONTWAIT);
|
||||||
assert(rc == 1);
|
assert(rc == 1);
|
||||||
assert(buffer[0] == 'B');
|
assert(buffer[0] == 'B');
|
||||||
|
|
||||||
// Clean up.
|
// Clean up.
|
||||||
rc = zmq_close (pub);
|
rc = zmq_close (pub);
|
||||||
|
@ -42,7 +42,7 @@ int main (void)
|
|||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
// set pub socket options
|
// set pub socket options
|
||||||
rc = zmq_setsockopt(pub, ZMQ_XPUB_WELCOME_MSG, "W", 1);
|
rc = zmq_setsockopt(pub, ZMQ_XPUB_WELCOME_MSG, "W", 1);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
// Create a subscriber
|
// Create a subscriber
|
||||||
|
Loading…
x
Reference in New Issue
Block a user