From 60d709bea971bd99d3b6727465aa0ead0d00beba Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Sat, 25 Feb 2012 16:04:52 +0100 Subject: 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 --- src/xrep.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') 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); } } -- cgit v1.2.3