summaryrefslogtreecommitdiff
path: root/src/ctx.cpp
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2010-09-01 07:57:38 +0200
committerMartin Sustrik <sustrik@250bpm.com>2010-09-01 07:57:38 +0200
commitce0972dca3982538fd123b61fbae3928fad6d1e7 (patch)
treef15d4de3c7dd2aadc3c25b6f8a602c4fe64a334d /src/ctx.cpp
parentdb73c76314d7109da4b400a3edb107c4eda802a2 (diff)
context creates an inproc endpoint ('inproc://log') to distribute 0MQ's log messages
Diffstat (limited to 'src/ctx.cpp')
-rw-r--r--src/ctx.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/ctx.cpp b/src/ctx.cpp
index 79145eb..f66e1fe 100644
--- a/src/ctx.cpp
+++ b/src/ctx.cpp
@@ -20,8 +20,6 @@
#include <new>
#include <string.h>
-#include "../include/zmq.h"
-
#include "ctx.hpp"
#include "socket_base.hpp"
#include "io_thread.hpp"
@@ -68,6 +66,12 @@ zmq::ctx_t::ctx_t (uint32_t io_threads_) :
empty_slots.push_back (i);
slots [i] = NULL;
}
+
+ // Create the logging infrastructure.
+ log_socket = create_socket (ZMQ_PUB);
+ zmq_assert (log_socket);
+ int rc = log_socket->bind ("inproc://log");
+ zmq_assert (rc == 0);
}
zmq::ctx_t::~ctx_t ()
@@ -104,6 +108,13 @@ int zmq::ctx_t::terminate ()
for (sockets_t::size_type i = 0; i != sockets.size (); i++)
sockets [i]->stop ();
+ // Close the logging infrastructure.
+ log_sync.lock ();
+ int rc = log_socket->close ();
+ zmq_assert (rc == 0);
+ log_socket = NULL;
+ log_sync.unlock ();
+
// Find out whether there are any open sockets to care about.
// If so, sleep till they are closed. Note that we can use
// no_sockets_notify safely out of the critical section as once set
@@ -287,6 +298,16 @@ zmq::socket_base_t *zmq::ctx_t::find_endpoint (const char *addr_)
return endpoint;
}
+void zmq::ctx_t::log (zmq_msg_t *msg_)
+{
+ // At this point we migrate the log socket to the current thread.
+ // We rely on mutex for executing the memory barrier.
+ log_sync.lock ();
+ if (log_socket)
+ log_socket->send (msg_, 0);
+ log_sync.unlock ();
+}
+
void zmq::ctx_t::dezombify ()
{
// Try to dezombify each zombie in the list. Note that caller is