[zeromq-dev] [PATCH] drop connections with duplicate peer IDs

Dhammika Pathirana dhammika at gmail.com
Tue Oct 26 08:20:55 CEST 2010


Hi,

Patches for issue #30


>From f77b8e1ed020786c36216c819fb38d78d5a57d46 Mon Sep 17 00:00:00 2001
From: dhammika <dhammika at gmail.com>
Date: Mon, 25 Oct 2010 22:19:43 -0700
Subject: [PATCH] drop connection requests with duplicate peer identity


Signed-off-by: dhammika <dhammika at gmail.com>
---
 src/session.cpp  |    9 +++++++--
 src/zmq_init.hpp |    2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/session.cpp b/src/session.cpp
index f853d5a..98e3c49 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -231,6 +231,13 @@ void zmq::session_t::process_attach (i_engine *engine_,
         return;
     }

+    //  If the session already has an engine attached, destroy new one.
+    //  Note new engine is not plugged in yet, we don't have to unplug it.
+    if (engine) {
+        delete engine_;
+        return;
+    }
+
     //  Check whether the required pipes already exist. If not so, we'll
     //  create them and bind them to the socket object.
     if (!pipes_attached) {
@@ -257,8 +264,6 @@ void zmq::session_t::process_attach (i_engine *engine_,
     }

     //  Plug in the engine.
-    zmq_assert (!engine);
-    zmq_assert (engine_);
     engine = engine_;
     engine->plug (io_thread, this);

diff --git a/src/zmq_init.hpp b/src/zmq_init.hpp
index 6087de9..2233b7b 100644
--- a/src/zmq_init.hpp
+++ b/src/zmq_init.hpp
@@ -55,7 +55,7 @@ namespace zmq
         void process_plug ();
         void process_unplug ();

-        //  Associated wite-protocol engine.
+        //  Associated wire-protocol engine.
         i_engine *engine;

         //  True if our own identity was already sent to the peer.
-- 
1.7.0.4


>From 2f1de7f95aeae3b40fc1c851f052c7c0c0b9dee7 Mon Sep 17 00:00:00 2001
From: dhammika <dhammika at gmail.com>
Date: Mon, 25 Oct 2010 23:12:56 -0700
Subject: [PATCH 2/2] fix typo, destroy new engine


Signed-off-by: dhammika <dhammika at gmail.com>
---
 src/session.cpp |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/session.cpp b/src/session.cpp
index 98e3c49..652cc05 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -227,7 +227,7 @@ void zmq::session_t::process_attach (i_engine *engine_,
     //  Note that we don't have to unplug it before deleting as it's not
     //  yet plugged to the session.
     if (state == terminating) {
-        delete engine;
+        delete engine_;
         return;
     }

-- 
1.7.0.4



More information about the zeromq-dev mailing list