mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-28 19:52:00 +01:00
Problem: libzmq does not send ZMTP 3.1 sub/cancel commands
Solution: if all peers of a socket are >= 3.1 use sub/cancel commands instead of the old 0/1 messages. For backward compatibility, move the handling of 0/1 or sub/cancel command strings to the encoders, so that the right thing can be done depending on the protocol version. Do not set the command flag until the encoder, so that we can handle the inproc case (which skips the encoder).
This commit is contained in:
16
src/sub.cpp
16
src/sub.cpp
@@ -56,15 +56,15 @@ int zmq::sub_t::xsetsockopt (int option_,
|
||||
|
||||
// Create the subscription message.
|
||||
msg_t msg;
|
||||
int rc = msg.init_size (optvallen_ + 1);
|
||||
errno_assert (rc == 0);
|
||||
unsigned char *data = static_cast<unsigned char *> (msg.data ());
|
||||
*data = (option_ == ZMQ_SUBSCRIBE);
|
||||
// We explicitly allow a NULL subscription with size zero
|
||||
if (optvallen_) {
|
||||
assert (optval_);
|
||||
memcpy (data + 1, optval_, optvallen_);
|
||||
int rc;
|
||||
const unsigned char *data = static_cast<const unsigned char *> (optval_);
|
||||
if (option_ == ZMQ_SUBSCRIBE) {
|
||||
rc = msg.init_subscribe (optvallen_, data);
|
||||
} else {
|
||||
rc = msg.init_cancel (optvallen_, data);
|
||||
}
|
||||
errno_assert (rc == 0);
|
||||
|
||||
// Pass it further on in the stack.
|
||||
rc = xsub_t::xsend (&msg);
|
||||
return close_and_return (&msg, rc);
|
||||
|
||||
Reference in New Issue
Block a user