On Thu, Feb 17, 2011 at 4:42 PM, Martin Sustrik <[email protected]> wrote:

> I would remove the throttling mechanism. It has to be much more fine-grain
> (such as per-session throttling), so let's ommit for now.

OK, new patch without the throttling. Simpler is better.

-Pieter
From 606fb49dca15fcc44f9018f30415c13abaa2251f Mon Sep 17 00:00:00 2001
From: Pieter Hintjens <[email protected]>
Date: Thu, 17 Feb 2011 16:23:01 +0100
Subject: [PATCH 149/149] Added syslog reporting of some major events in 0MQ

- log method in object base class sends formatted report to sys://log.
- xrep warns when it cannot route a message due to an unknown envelope identity
- session warns when it disconnects a peer due to duplicate identity

Signed-off-by: Pieter Hintjens <[email protected]>
---
 src/object.cpp  |   30 ++++++++++++++++++++++++++++--
 src/object.hpp  |    4 ++--
 src/session.cpp |    1 +
 src/xrep.cpp    |    2 ++
 4 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/src/object.cpp b/src/object.cpp
index 9ec73f7..c597712 100644
--- a/src/object.cpp
+++ b/src/object.cpp
@@ -151,9 +151,35 @@ void zmq::object_t::destroy_socket (socket_base_t *socket_)
     ctx->destroy_socket (socket_);
 }
 
-void zmq::object_t::log (zmq_msg_t *msg_)
-{
-    ctx->log (msg_);
+//  Sends the string to sys://log, and if the identity is not null
+//  reports that as a readable string.
+//
+void zmq::object_t::log (const char *string_, const blob_t &identity_)
+{
+    //  We log errors in 0MQ string format, with trailing null byte
+    //  First four characters of string are error identifier
+    //  We discard duplicates to avoid error message storms
+    ::zmq_msg_t msg;
+    std::string report = "";
+
+    report += string_;
+    if (&identity_) {
+        report += " (identity = 0x";
+        for (uint i = 0; i < identity_.length() && i < 32; i++) {
+            const char hex [] = "0123456789ABCDEF";
+            report += hex [identity_[i] >> 4];
+            report += hex [identity_[i] & 15];
+        }
+        report += ", \"";
+        for (uint i = 0; i < identity_.length() && i < 32; i++)
+            report += isprint (identity_[i])? identity_[i]: '.';
+        report += "\")\0";
+    }
+    //  Log the error message
+    zmq_msg_init_size (&msg, report.length ());
+    memcpy (zmq_msg_data (&msg), report.c_str (), report.length ());
+    ctx->log (&msg);
+    zmq_msg_close (&msg);
 }
 
 zmq::io_thread_t *zmq::object_t::choose_io_thread (uint64_t affinity_)
diff --git a/src/object.hpp b/src/object.hpp
index 748a339..6186d74 100644
--- a/src/object.hpp
+++ b/src/object.hpp
@@ -51,8 +51,8 @@ namespace zmq
         struct endpoint_t find_endpoint (const char *addr_);
         void destroy_socket (class socket_base_t *socket_);
 
-        //  Logs an message.
-        void log (zmq_msg_t *msg_);
+        //  Logs a system error string
+        void log (const char *string_, const blob_t &identity_);
 
         //  Chooses least loaded I/O thread.
         class io_thread_t *choose_io_thread (uint64_t affinity_);
diff --git a/src/session.cpp b/src/session.cpp
index 350d043..fb0cd5a 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -234,6 +234,7 @@ void zmq::session_t::process_attach (i_engine *engine_,
     //  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) {
+        log ("DPID: duplicate peer identity - disconnecting peer", peer_identity_);
         delete engine_;
         return;
     }
diff --git a/src/xrep.cpp b/src/xrep.cpp
index 9c985c0..135630d 100644
--- a/src/xrep.cpp
+++ b/src/xrep.cpp
@@ -178,6 +178,8 @@ int zmq::xrep_t::xsend (zmq_msg_t *msg_, int flags_)
             outpipes_t::iterator it = outpipes.find (identity);
             if (it != outpipes.end ())
                 current_out = it->second.writer;
+            else
+                log ("IDNF: no such identity, cannot route message - discarding", identity);
         }
 
         int rc = zmq_msg_close (msg_);
-- 
1.7.0.4

_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to