work in progress...

This commit is contained in:
H. Eduardo Montoya Sánchez 2013-01-30 15:22:54 +01:00
parent 9f7a5f18d1
commit bcdf163fa8

40
zmq.hpp
View File

@ -296,7 +296,7 @@ namespace zmq
{ {
public: public:
inline socket_t (context_t &context_, int type_) inline socket_t (context_t &context_, int type_) : is_monitored(false)
{ {
ptr = zmq_socket (context_.ptr, type_); ptr = zmq_socket (context_.ptr, type_);
if (ptr == NULL) if (ptr == NULL)
@ -304,7 +304,7 @@ namespace zmq
} }
#ifdef ZMQ_HAS_RVALUE_REFS #ifdef ZMQ_HAS_RVALUE_REFS
inline socket_t(socket_t&& rhs) : ptr(rhs.ptr) inline socket_t(socket_t&& rhs) : ptr(rhs.ptr), is_monitored(false)
{ {
rhs.ptr = NULL; rhs.ptr = NULL;
} }
@ -351,16 +351,24 @@ namespace zmq
throw error_t (); throw error_t ();
} }
inlinde void init_monitor(const char *addr_)
{
std::string myaddr = std::string(addr_);
std::string monaddr = "inproc://monitor/" + myaddr;
rc = zmq_socket_monitor (ptr, monaddr.c_str(), ZMQ_EVENT_ALL);
if (rc != 0)
throw error_t ();
}
inline void bind (const char *addr_) inline void bind (const char *addr_)
{ {
int rc = zmq_bind (ptr, addr_); int rc = zmq_bind (ptr, addr_);
if (rc != 0) if (rc != 0)
throw error_t (); throw error_t ();
myaddr = std::string(addr_); if (is_monitored)
monaddr = "inproc://monitor/" + myaddr; {
rc = zmq_socket_monitor (ptr, monaddr.c_str(), ZMQ_EVENT_ALL); init_monitor()
if (rc != 0) }
throw error_t ();
} }
inline void connect (const char *addr_) inline void connect (const char *addr_)
@ -368,11 +376,10 @@ namespace zmq
int rc = zmq_connect (ptr, addr_); int rc = zmq_connect (ptr, addr_);
if (rc != 0) if (rc != 0)
throw error_t (); throw error_t ();
myaddr = std::string(addr_); if (is_monitored)
monaddr = "inproc://monitor/" + myaddr; {
rc = zmq_socket_monitor (ptr, monaddr.c_str(), ZMQ_EVENT_ALL); init_monitor()
if (rc != 0) }
throw error_t ();
} }
inline bool connected() inline bool connected()
@ -404,7 +411,7 @@ namespace zmq
switch (event.event) { switch (event.event) {
case ZMQ_EVENT_CONNECTED: case ZMQ_EVENT_CONNECTED:
mon->on_event_connected(); mon->on_event_connected(event.connected.addr);
break; break;
case ZMQ_EVENT_CONNECT_DELAYED: case ZMQ_EVENT_CONNECT_DELAYED:
mon->on_event_connect_delayed(); mon->on_event_connect_delayed();
@ -484,8 +491,13 @@ namespace zmq
throw error_t (); throw error_t ();
} }
private: inline void enable_monitoring()
{
is_monitored = true;
}
private:
bool is_monitored;
void *ptr; void *ptr;
monitor_t *mon; monitor_t *mon;
std::string monaddr; std::string monaddr;