Added assert on duplicate id in ROUTER and STREAM sockets. Updated man to reflect this change. Modified test case to match.

This commit is contained in:
Tim M 2014-01-21 11:43:34 -08:00
parent 141e1b5966
commit 515af9b147
4 changed files with 11 additions and 18 deletions

View File

@ -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 subsequent call to zmq_connect(), calls thereafter use default connection
behavior. behavior.
Typical use is to set this socket option on each zmq_connect() attempt Typical use is to set this socket option ahead of each zmq_connect() attempt
to a new host. Each connection should be assigned a unique name. Duplicated to a new host. Each connection MUST be assigned a unique name. Assigning a
names will trigger default connection behavior. name that is already in use is not allowed.
Useful when connecting ROUTER to ROUTER, or STREAM to STREAM, as it Useful when connecting ROUTER to ROUTER, or STREAM to STREAM, as it
allows for immediate sending to peers. Outbound id framing requirements allows for immediate sending to peers. Outbound id framing requirements

View File

@ -393,9 +393,8 @@ bool zmq::router_t::identify_peer (pipe_t *pipe_)
connect_rid.length()); connect_rid.length());
connect_rid.clear (); connect_rid.clear ();
outpipes_t::iterator it = outpipes.find (identity); outpipes_t::iterator it = outpipes.find (identity);
if (it != outpipes.end ()) { if (it != outpipes.end ())
return false; // duplicate connection zmq_assert(false); // Not allowed to duplicate an existing rid
}
} }
else else
if (options.raw_sock) { // Always assign identity for raw-socket if (options.raw_sock) { // Always assign identity for raw-socket

View File

@ -268,10 +268,10 @@ void zmq::stream_t::identify_peer (pipe_t *pipe_)
connect_rid.clear (); connect_rid.clear ();
outpipes_t::iterator it = outpipes.find (identity); outpipes_t::iterator it = outpipes.find (identity);
if (it != outpipes.end ()) if (it != outpipes.end ())
goto d; zmq_assert(false);
} }
else { else {
d: put_uint32 (buffer + 1, next_rid++); put_uint32 (buffer + 1, next_rid++);
identity = blob_t (buffer, sizeof buffer); identity = blob_t (buffer, sizeof buffer);
memcpy (options.identity, identity.data (), identity.size ()); memcpy (options.identity, identity.data (), identity.size ());
options.identity_size = identity.size (); options.identity_size = identity.size ();

View File

@ -47,12 +47,13 @@ void test_stream_2_stream(void* ctx_){
assert (0 == ret); assert (0 == ret);
ret = zmq_connect (rconn1, bindip); ret = zmq_connect (rconn1, bindip);
/* Uncomment to test assert on duplicate rid.
// Test duplicate connect attempt. // Test duplicate connect attempt.
ret = zmq_setsockopt (rconn1, ZMQ_CONNECT_RID, "conn1", 6); ret = zmq_setsockopt (rconn1, ZMQ_CONNECT_RID, "conn1", 6);
assert (0 == ret); assert (0 == ret);
ret = zmq_connect (rconn1, bindip); ret = zmq_connect (rconn1, bindip);
assert (0 == ret); assert (0 == ret);
*/
// Send data to the bound stream. // Send data to the bound stream.
ret = zmq_send (rconn1, "conn1", 6, ZMQ_SNDMORE); ret = zmq_send (rconn1, "conn1", 6, ZMQ_SNDMORE);
assert (6 == ret); assert (6 == ret);
@ -66,13 +67,6 @@ void test_stream_2_stream(void* ctx_){
ret = zmq_recv (rbind, buff, 256, 0); ret = zmq_recv (rbind, buff, 256, 0);
assert (0 == ret); 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. // Handle close of the socket.
ret = zmq_recv (rbind, buff, 256, 0); ret = zmq_recv (rbind, buff, 256, 0);
assert (ret); assert (ret);
@ -119,13 +113,13 @@ void test_router_2_router(void* ctx,bool named){
assert (0 == ret); assert (0 == ret);
ret = zmq_connect (rconn1, bindip); ret = zmq_connect (rconn1, bindip);
assert (0 == ret); assert (0 == ret);
/* Uncomment to test assert on duplicate rid
// Test duplicate connect attempt. // Test duplicate connect attempt.
ret = zmq_setsockopt (rconn1, ZMQ_CONNECT_RID, "conn1", 6); ret = zmq_setsockopt (rconn1, ZMQ_CONNECT_RID, "conn1", 6);
assert (0 == ret); assert (0 == ret);
ret = zmq_connect (rconn1, bindip); ret = zmq_connect (rconn1, bindip);
assert (0 == ret); assert (0 == ret);
*/
// Send some data. // Send some data.
ret = zmq_send (rconn1, "conn1", 6, ZMQ_SNDMORE); ret = zmq_send (rconn1, "conn1", 6, ZMQ_SNDMORE);
assert (6 == ret); assert (6 == ret);