summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2012-02-25 16:04:52 +0100
committerMartin Sustrik <sustrik@250bpm.com>2012-02-26 13:05:59 +0100
commit60d709bea971bd99d3b6727465aa0ead0d00beba (patch)
tree691fdedc2ff28cc8f586eb3a1f7a9617d336faa1
parente5acca89b6352caa6d5022f11f63dfafcfa146d7 (diff)
In case of duplicate identity XREP socket asserts.
This is a fail-fast mechanism to prevent undefined behaviour later on. In the future, the new connection should be closed in this case. Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
-rw-r--r--src/xrep.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/xrep.cpp b/src/xrep.cpp
index 9c5aa44..f8565de 100644
--- a/src/xrep.cpp
+++ b/src/xrep.cpp
@@ -218,6 +218,7 @@ int xs::xrep_t::xrecv (msg_t *msg_, int flags_)
if (msg_->size () != 0) {
// Actual change of the identity.
+ bool changed = false;
outpipes_t::iterator it = outpipes.begin ();
while (it != outpipes.end ()) {
if (it->second.pipe == pipe) {
@@ -226,13 +227,19 @@ int xs::xrep_t::xrecv (msg_t *msg_, int flags_)
pipe->set_identity (identity);
outpipes.erase (it);
outpipe_t outpipe = {pipe, true};
- it = outpipes.insert (outpipes_t::value_type (identity,
- outpipe)).first;
+ if (!outpipes.insert (outpipes_t::value_type (identity,
+ outpipe)).second) {
+
+ // Duplicate identity.
+ // TODO: Drop the new connection.
+ xs_assert (false);
+ }
+ changed = true;
break;
}
++it;
}
- xs_assert (it != outpipes.end ());
+ xs_assert (changed);
}
}