mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-22 16:02:31 +02:00
ZMQ_MONITOR socket option registers a callback / event sink for changes in socket state
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include "ip.hpp"
|
||||
#include "address.hpp"
|
||||
#include "ipc_address.hpp"
|
||||
#include "session_base.hpp"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
@@ -53,6 +54,7 @@ zmq::ipc_connecter_t::ipc_connecter_t (class io_thread_t *io_thread_,
|
||||
{
|
||||
zmq_assert (addr);
|
||||
zmq_assert (addr->protocol == "ipc");
|
||||
addr->to_string (endpoint);
|
||||
}
|
||||
|
||||
zmq::ipc_connecter_t::~ipc_connecter_t ()
|
||||
@@ -105,6 +107,8 @@ void zmq::ipc_connecter_t::out_event ()
|
||||
|
||||
// Shut the connecter down.
|
||||
terminate ();
|
||||
|
||||
session->monitor_event (ZMQ_EVENT_CONNECTED, endpoint.c_str(), fd);
|
||||
}
|
||||
|
||||
void zmq::ipc_connecter_t::timer_event (int id_)
|
||||
@@ -132,6 +136,7 @@ void zmq::ipc_connecter_t::start_connecting ()
|
||||
handle = add_fd (s);
|
||||
handle_valid = true;
|
||||
set_pollout (handle);
|
||||
session->monitor_event (ZMQ_EVENT_CONNECT_DELAYED, endpoint.c_str(), zmq_errno());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -143,7 +148,9 @@ void zmq::ipc_connecter_t::start_connecting ()
|
||||
|
||||
void zmq::ipc_connecter_t::add_reconnect_timer()
|
||||
{
|
||||
add_timer (get_new_reconnect_ivl(), reconnect_timer_id);
|
||||
int rc_ivl = get_new_reconnect_ivl();
|
||||
add_timer (rc_ivl, reconnect_timer_id);
|
||||
session->monitor_event (ZMQ_EVENT_CONNECT_RETRIED, endpoint.c_str(), rc_ivl);
|
||||
}
|
||||
|
||||
int zmq::ipc_connecter_t::get_new_reconnect_ivl ()
|
||||
@@ -195,8 +202,11 @@ int zmq::ipc_connecter_t::close ()
|
||||
{
|
||||
zmq_assert (s != retired_fd);
|
||||
int rc = ::close (s);
|
||||
if (rc != 0)
|
||||
if (rc != 0) {
|
||||
session->monitor_event (ZMQ_EVENT_CLOSE_FAILED, endpoint.c_str(), zmq_errno());
|
||||
return -1;
|
||||
}
|
||||
session->monitor_event (ZMQ_EVENT_CLOSED, endpoint.c_str(), s);
|
||||
s = retired_fd;
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user