mirror of
https://github.com/zeromq/libzmq.git
synced 2025-11-06 05:00:07 +01:00
Problem: ZMQ_PUB broken on ZMQ_WS
Solution: encode subscribe/cancel messages until there are appropriate
opcodes.
Regression introduced by 253e9dd27b
Fixes https://github.com/zeromq/libzmq/issues/4101
This commit is contained in:
@@ -73,6 +73,9 @@ void zmq::ws_encoder_t::message_ready ()
|
||||
size_t size = in_progress ()->size ();
|
||||
if (_is_binary)
|
||||
size++;
|
||||
// TODO: create an opcode for subscribe/cancel
|
||||
if (in_progress ()->is_subscribe () || in_progress ()->is_cancel ())
|
||||
size++;
|
||||
|
||||
if (size <= 125)
|
||||
_tmp_buf[offset++] |= static_cast<unsigned char> (size & 127);
|
||||
@@ -93,6 +96,7 @@ void zmq::ws_encoder_t::message_ready ()
|
||||
offset += 4;
|
||||
}
|
||||
|
||||
int mask_index = 0;
|
||||
if (_is_binary) {
|
||||
// Encode flags.
|
||||
unsigned char protocol_flags = 0;
|
||||
@@ -102,9 +106,16 @@ void zmq::ws_encoder_t::message_ready ()
|
||||
protocol_flags |= ws_protocol_t::command_flag;
|
||||
|
||||
_tmp_buf[offset++] =
|
||||
_must_mask ? protocol_flags ^ _mask[0] : protocol_flags;
|
||||
_must_mask ? protocol_flags ^ _mask[mask_index++] : protocol_flags;
|
||||
}
|
||||
|
||||
// Encode the subscribe/cancel byte.
|
||||
// TODO: remove once there is an opcode for subscribe/cancel
|
||||
if (in_progress ()->is_subscribe ())
|
||||
_tmp_buf[offset++] = _must_mask ? 1 ^ _mask[mask_index++] : 1;
|
||||
else if (in_progress ()->is_cancel ())
|
||||
_tmp_buf[offset++] = _must_mask ? 0 ^ _mask[mask_index++] : 0;
|
||||
|
||||
next_step (_tmp_buf, offset, &ws_encoder_t::size_ready, false);
|
||||
}
|
||||
|
||||
@@ -126,7 +137,12 @@ void zmq::ws_encoder_t::size_ready ()
|
||||
dest = static_cast<unsigned char *> (_masked_msg.data ());
|
||||
}
|
||||
|
||||
int mask_index = _is_binary ? 1 : 0;
|
||||
int mask_index = 0;
|
||||
if (_is_binary)
|
||||
++mask_index;
|
||||
// TODO: remove once there is an opcode for subscribe/cancel
|
||||
if (in_progress ()->is_subscribe () || in_progress ()->is_cancel ())
|
||||
++mask_index;
|
||||
for (size_t i = 0; i < size; ++i, mask_index++)
|
||||
dest[i] = src[i] ^ _mask[mask_index % 4];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user