0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-27 23:51:04 +08:00

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.
This commit is contained in:
Pieter Hintjens 2014-05-15 16:31:32 +02:00
parent adddda17cf
commit a178097f95
2 changed files with 3 additions and 6 deletions

View File

@ -190,7 +190,7 @@ ZMQ_IDENTITY: Set socket identity
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
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
results shall depend on the ZMQ_ROUTER_HANDOVER option setting. If that

View File

@ -89,11 +89,8 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
break;
case ZMQ_IDENTITY:
// Empty identity is invalid as well as identity longer than
// 255 bytes. Identity starting with binary zero is invalid
// as these are used for auto-generated identities.
if (optvallen_ > 0 && optvallen_ < 256
&& *((const unsigned char *) optval_) != 0) {
// Identity is any binary string from 1 to 255 octets
if (optvallen_ > 0 && optvallen_ < 256) {
identity_size = optvallen_;
memcpy (identity, optval_, identity_size);
return 0;