Logging of duplicit identities added

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
This commit is contained in:
Martin Sustrik 2011-02-18 14:15:10 +01:00
parent 1f536b2d38
commit 17e2ca71b4
5 changed files with 20 additions and 6 deletions

View File

@ -291,14 +291,22 @@ zmq::endpoint_t zmq::ctx_t::find_endpoint (const char *addr_)
return *endpoint; return *endpoint;
} }
void zmq::ctx_t::log (zmq_msg_t *msg_) void zmq::ctx_t::log (const char *format_, va_list args_)
{ {
// Create the log message.
zmq_msg_t msg;
int rc = zmq_msg_init_size (&msg, strlen (format_) + 1);
zmq_assert (rc == 0);
memcpy (zmq_msg_data (&msg), format_, zmq_msg_size (&msg));
// At this point we migrate the log socket to the current thread. // At this point we migrate the log socket to the current thread.
// We rely on mutex for executing the memory barrier. // We rely on mutex for executing the memory barrier.
log_sync.lock (); log_sync.lock ();
if (log_socket) if (log_socket)
log_socket->send (msg_, 0); log_socket->send (&msg, 0);
log_sync.unlock (); log_sync.unlock ();
zmq_msg_close (&msg);
} }

View File

@ -23,6 +23,7 @@
#include <map> #include <map>
#include <vector> #include <vector>
#include <string> #include <string>
#include <stdarg.h>
#include "../include/zmq.h" #include "../include/zmq.h"
@ -85,7 +86,7 @@ namespace zmq
endpoint_t find_endpoint (const char *addr_); endpoint_t find_endpoint (const char *addr_);
// Logging. // Logging.
void log (zmq_msg_t *msg_); void log (const char *format_, va_list args_);
enum { enum {
term_tid = 0, term_tid = 0,

View File

@ -18,6 +18,7 @@
*/ */
#include <string.h> #include <string.h>
#include <stdarg.h>
#include "object.hpp" #include "object.hpp"
#include "ctx.hpp" #include "ctx.hpp"
@ -151,9 +152,12 @@ void zmq::object_t::destroy_socket (socket_base_t *socket_)
ctx->destroy_socket (socket_); ctx->destroy_socket (socket_);
} }
void zmq::object_t::log (zmq_msg_t *msg_) void zmq::object_t::log (const char *format_, ...)
{ {
ctx->log (msg_); va_list args;
va_start (args, format_);
ctx->log (format_, args);
va_end (args);
} }
zmq::io_thread_t *zmq::object_t::choose_io_thread (uint64_t affinity_) zmq::io_thread_t *zmq::object_t::choose_io_thread (uint64_t affinity_)

View File

@ -52,7 +52,7 @@ namespace zmq
void destroy_socket (class socket_base_t *socket_); void destroy_socket (class socket_base_t *socket_);
// Logs an message. // Logs an message.
void log (zmq_msg_t *msg_); void log (const char *format_, ...);
// Chooses least loaded I/O thread. // Chooses least loaded I/O thread.
class io_thread_t *choose_io_thread (uint64_t affinity_); class io_thread_t *choose_io_thread (uint64_t affinity_);

View File

@ -234,6 +234,7 @@ void zmq::session_t::process_attach (i_engine *engine_,
// If the session already has an engine attached, destroy new one. // 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. // Note new engine is not plugged in yet, we don't have to unplug it.
if (engine) { if (engine) {
log ("DPID: duplicate peer identity - disconnecting peer");
delete engine_; delete engine_;
return; return;
} }