diff --git a/doc/zmq_setsockopt.txt b/doc/zmq_setsockopt.txt index 5ad3077d..bb881df7 100644 --- a/doc/zmq_setsockopt.txt +++ b/doc/zmq_setsockopt.txt @@ -75,9 +75,9 @@ data transfer with the named id. This option applies only to the first subsequent call to zmq_connect(), calls thereafter use default connection behavior. -Typical use is to set this socket option on each zmq_connect() attempt -to a new host. Each connection should be assigned a unique name. Duplicated -names will trigger default connection behavior. +Typical use is to set this socket option ahead of each zmq_connect() attempt +to a new host. Each connection MUST be assigned a unique name. Assigning a +name that is already in use is not allowed. Useful when connecting ROUTER to ROUTER, or STREAM to STREAM, as it allows for immediate sending to peers. Outbound id framing requirements diff --git a/src/router.cpp b/src/router.cpp index 4a9614b5..fc1035e8 100644 --- a/src/router.cpp +++ b/src/router.cpp @@ -393,9 +393,8 @@ bool zmq::router_t::identify_peer (pipe_t *pipe_) connect_rid.length()); connect_rid.clear (); outpipes_t::iterator it = outpipes.find (identity); - if (it != outpipes.end ()) { - return false; // duplicate connection - } + if (it != outpipes.end ()) + zmq_assert(false); // Not allowed to duplicate an existing rid } else if (options.raw_sock) { // Always assign identity for raw-socket diff --git a/src/stream.cpp b/src/stream.cpp index 2e0ecba5..8a00c963 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -268,10 +268,10 @@ void zmq::stream_t::identify_peer (pipe_t *pipe_) connect_rid.clear (); outpipes_t::iterator it = outpipes.find (identity); if (it != outpipes.end ()) - goto d; + zmq_assert(false); } else { -d: put_uint32 (buffer + 1, next_rid++); + put_uint32 (buffer + 1, next_rid++); identity = blob_t (buffer, sizeof buffer); memcpy (options.identity, identity.data (), identity.size ()); options.identity_size = identity.size (); diff --git a/tests/test_connect_rid.cpp b/tests/test_connect_rid.cpp index 7c620c1e..5c5798a3 100644 --- a/tests/test_connect_rid.cpp +++ b/tests/test_connect_rid.cpp @@ -47,12 +47,13 @@ void test_stream_2_stream(void* ctx_){ assert (0 == ret); ret = zmq_connect (rconn1, bindip); +/* Uncomment to test assert on duplicate rid. // Test duplicate connect attempt. ret = zmq_setsockopt (rconn1, ZMQ_CONNECT_RID, "conn1", 6); assert (0 == ret); ret = zmq_connect (rconn1, bindip); assert (0 == ret); - +*/ // Send data to the bound stream. ret = zmq_send (rconn1, "conn1", 6, ZMQ_SNDMORE); assert (6 == ret); @@ -66,13 +67,6 @@ void test_stream_2_stream(void* ctx_){ ret = zmq_recv (rbind, buff, 256, 0); assert (0 == ret); - // Close the duplicate socket. - ret = zmq_recv (rbind, buff, 256, 0); - assert (ret); - assert (0 == buff[0]); - ret = zmq_recv (rbind, buff+128, 128, 0); - assert (0 == ret); - // Handle close of the socket. ret = zmq_recv (rbind, buff, 256, 0); assert (ret); @@ -119,13 +113,13 @@ void test_router_2_router(void* ctx,bool named){ assert (0 == ret); ret = zmq_connect (rconn1, bindip); assert (0 == ret); - +/* Uncomment to test assert on duplicate rid // Test duplicate connect attempt. ret = zmq_setsockopt (rconn1, ZMQ_CONNECT_RID, "conn1", 6); assert (0 == ret); ret = zmq_connect (rconn1, bindip); assert (0 == ret); - +*/ // Send some data. ret = zmq_send (rconn1, "conn1", 6, ZMQ_SNDMORE); assert (6 == ret);