Commit a178097f authored by Pieter Hintjens's avatar Pieter Hintjens

Problem: artificial restriction on binary identities

Applications that use ZMQ_IDENTITY can be trapped by the artificial
restriction on not using a binary zero as first byte. It's specially
nasty on random generated identities, e.g. UUIDs, as the chance of a
binary zero is low, so it will pass 255 out of 256 times.

Solution: remove the restriction.
parent adddda17
...@@ -190,7 +190,7 @@ ZMQ_IDENTITY: Set socket identity ...@@ -190,7 +190,7 @@ ZMQ_IDENTITY: Set socket identity
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The 'ZMQ_IDENTITY' option shall set the identity of the specified 'socket' The 'ZMQ_IDENTITY' option shall set the identity of the specified 'socket'
when connecting to a ROUTER socket. The identity should be from 1 to 255 when connecting to a ROUTER socket. The identity should be from 1 to 255
bytes long and MAY NOT start with binary zero. bytes long and may contain any values.
If two clients use the same identity when connecting to a ROUTER, the If two clients use the same identity when connecting to a ROUTER, the
results shall depend on the ZMQ_ROUTER_HANDOVER option setting. If that results shall depend on the ZMQ_ROUTER_HANDOVER option setting. If that
......
...@@ -89,11 +89,8 @@ int zmq::options_t::setsockopt (int option_, const void *optval_, ...@@ -89,11 +89,8 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
break; break;
case ZMQ_IDENTITY: case ZMQ_IDENTITY:
// Empty identity is invalid as well as identity longer than // Identity is any binary string from 1 to 255 octets
// 255 bytes. Identity starting with binary zero is invalid if (optvallen_ > 0 && optvallen_ < 256) {
// as these are used for auto-generated identities.
if (optvallen_ > 0 && optvallen_ < 256
&& *((const unsigned char *) optval_) != 0) {
identity_size = optvallen_; identity_size = optvallen_;
memcpy (identity, optval_, identity_size); memcpy (identity, optval_, identity_size);
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment