mirror of
https://github.com/zeromq/libzmq.git
synced 2025-01-19 00:46:05 +01:00
Merge pull request #1037 from hintjens/master
Problem: artificial restriction on binary identities
This commit is contained in:
commit
045dab91a5
@ -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
|
||||
|
@ -42,7 +42,8 @@
|
||||
int clipped_maxsocket(int max_requested)
|
||||
{
|
||||
if (max_requested >= zmq::poller_t::max_fds () && zmq::poller_t::max_fds () != -1)
|
||||
max_requested = zmq::poller_t::max_fds () - 1; // -1 because we need room for the repear mailbox.
|
||||
// -1 because we need room for the reaper mailbox.
|
||||
max_requested = zmq::poller_t::max_fds () - 1;
|
||||
|
||||
return max_requested;
|
||||
}
|
||||
@ -175,7 +176,8 @@ int zmq::ctx_t::shutdown ()
|
||||
int zmq::ctx_t::set (int option_, int optval_)
|
||||
{
|
||||
int rc = 0;
|
||||
if (option_ == ZMQ_MAX_SOCKETS && optval_ >= 1 && optval_ == clipped_maxsocket (optval_)) {
|
||||
if (option_ == ZMQ_MAX_SOCKETS
|
||||
&& optval_ >= 1 && optval_ == clipped_maxsocket (optval_)) {
|
||||
opt_sync.lock ();
|
||||
max_sockets = optval_;
|
||||
opt_sync.unlock ();
|
||||
@ -233,7 +235,7 @@ zmq::socket_base_t *zmq::ctx_t::create_socket (int type_)
|
||||
int ios = io_thread_count;
|
||||
opt_sync.unlock ();
|
||||
slot_count = mazmq + ios + 2;
|
||||
slots = (mailbox_t**) malloc (sizeof (mailbox_t*) * slot_count);
|
||||
slots = (mailbox_t **) malloc (sizeof (mailbox_t*) * slot_count);
|
||||
alloc_assert (slots);
|
||||
|
||||
// Initialise the infrastructure for zmq_ctx_term thread.
|
||||
|
@ -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;
|
||||
|
@ -24,7 +24,7 @@ static void pusher (void *ctx)
|
||||
// Connect first
|
||||
void *connectSocket = zmq_socket (ctx, ZMQ_PAIR);
|
||||
assert (connectSocket);
|
||||
int rc = zmq_connect (connectSocket, "inproc://a");
|
||||
int rc = zmq_connect (connectSocket, "inproc://sink");
|
||||
assert (rc == 0);
|
||||
|
||||
// Queue up some data
|
||||
@ -44,13 +44,13 @@ void test_bind_before_connect ()
|
||||
// Bind first
|
||||
void *bindSocket = zmq_socket (ctx, ZMQ_PAIR);
|
||||
assert (bindSocket);
|
||||
int rc = zmq_bind (bindSocket, "inproc://a");
|
||||
int rc = zmq_bind (bindSocket, "inproc://bbc");
|
||||
assert (rc == 0);
|
||||
|
||||
// Now connect
|
||||
void *connectSocket = zmq_socket (ctx, ZMQ_PAIR);
|
||||
assert (connectSocket);
|
||||
rc = zmq_connect (connectSocket, "inproc://a");
|
||||
rc = zmq_connect (connectSocket, "inproc://bbc");
|
||||
assert (rc == 0);
|
||||
|
||||
// Queue up some data
|
||||
@ -85,7 +85,7 @@ void test_connect_before_bind ()
|
||||
// Connect first
|
||||
void *connectSocket = zmq_socket (ctx, ZMQ_PAIR);
|
||||
assert (connectSocket);
|
||||
int rc = zmq_connect (connectSocket, "inproc://a");
|
||||
int rc = zmq_connect (connectSocket, "inproc://cbb");
|
||||
assert (rc == 0);
|
||||
|
||||
// Queue up some data
|
||||
@ -95,7 +95,7 @@ void test_connect_before_bind ()
|
||||
// Now bind
|
||||
void *bindSocket = zmq_socket (ctx, ZMQ_PAIR);
|
||||
assert (bindSocket);
|
||||
rc = zmq_bind (bindSocket, "inproc://a");
|
||||
rc = zmq_bind (bindSocket, "inproc://cbb");
|
||||
assert (rc == 0);
|
||||
|
||||
// Read pending message
|
||||
@ -126,7 +126,7 @@ void test_connect_before_bind_pub_sub ()
|
||||
// Connect first
|
||||
void *connectSocket = zmq_socket (ctx, ZMQ_PUB);
|
||||
assert (connectSocket);
|
||||
int rc = zmq_connect (connectSocket, "inproc://a");
|
||||
int rc = zmq_connect (connectSocket, "inproc://cbbps");
|
||||
assert (rc == 0);
|
||||
|
||||
// Queue up some data, this will be dropped
|
||||
@ -138,7 +138,7 @@ void test_connect_before_bind_pub_sub ()
|
||||
assert (bindSocket);
|
||||
rc = zmq_setsockopt (bindSocket, ZMQ_SUBSCRIBE, "", 0);
|
||||
assert (rc == 0);
|
||||
rc = zmq_bind (bindSocket, "inproc://a");
|
||||
rc = zmq_bind (bindSocket, "inproc://cbbps");
|
||||
assert (rc == 0);
|
||||
|
||||
// Wait for pub-sub connection to happen
|
||||
@ -182,7 +182,7 @@ void test_multiple_connects ()
|
||||
{
|
||||
connectSocket [i] = zmq_socket (ctx, ZMQ_PUSH);
|
||||
assert (connectSocket [i]);
|
||||
rc = zmq_connect (connectSocket [i], "inproc://a");
|
||||
rc = zmq_connect (connectSocket [i], "inproc://multiple");
|
||||
assert (rc == 0);
|
||||
|
||||
// Queue up some data
|
||||
@ -193,7 +193,7 @@ void test_multiple_connects ()
|
||||
// Now bind
|
||||
void *bindSocket = zmq_socket (ctx, ZMQ_PULL);
|
||||
assert (bindSocket);
|
||||
rc = zmq_bind (bindSocket, "inproc://a");
|
||||
rc = zmq_bind (bindSocket, "inproc://multiple");
|
||||
assert (rc == 0);
|
||||
|
||||
for (unsigned int i = 0; i < no_of_connects; ++i)
|
||||
@ -240,7 +240,7 @@ void test_multiple_threads ()
|
||||
// Now bind
|
||||
void *bindSocket = zmq_socket (ctx, ZMQ_PULL);
|
||||
assert (bindSocket);
|
||||
rc = zmq_bind (bindSocket, "inproc://a");
|
||||
rc = zmq_bind (bindSocket, "inproc://sink");
|
||||
assert (rc == 0);
|
||||
|
||||
for (unsigned int i = 0; i < no_of_threads; ++i)
|
||||
@ -277,13 +277,13 @@ void test_identity ()
|
||||
void *sc = zmq_socket (ctx, ZMQ_DEALER);
|
||||
assert (sc);
|
||||
|
||||
int rc = zmq_connect (sc, "inproc://a");
|
||||
int rc = zmq_connect (sc, "inproc://identity");
|
||||
assert (rc == 0);
|
||||
|
||||
void *sb = zmq_socket (ctx, ZMQ_ROUTER);
|
||||
assert (sb);
|
||||
|
||||
rc = zmq_bind (sb, "inproc://a");
|
||||
rc = zmq_bind (sb, "inproc://identity");
|
||||
assert (rc == 0);
|
||||
|
||||
// Send 2-part message.
|
||||
|
Loading…
x
Reference in New Issue
Block a user