ZMQ_MONITOR socket option registers a callback / event sink for changes in socket state

This commit is contained in:
Lourens Naudé
2012-05-04 02:32:46 +01:00
parent 16ec2868c5
commit 5c6f72c17c
26 changed files with 461 additions and 13 deletions

View File

@@ -53,6 +53,7 @@ zmq::options_t::options_t () :
tcp_keepalive_cnt (-1),
tcp_keepalive_idle (-1),
tcp_keepalive_intvl (-1),
monitor (NULL),
socket_id (0)
{
}
@@ -313,6 +314,20 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
return 0;
}
}
case ZMQ_MONITOR:
{
if (optvallen_ == 0 && optval_ == NULL) {
monitor = NULL;
return 0;
}
if (optvallen_ != sizeof (void *)) {
errno = EINVAL;
return -1;
}
monitor = ((zmq_monitor_fn*) optval_);
return 0;
}
}
errno = EINVAL;
return -1;
@@ -530,6 +545,14 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
*optvallen_ = last_endpoint.size()+1;
return 0;
case ZMQ_MONITOR:
if (*optvallen_ < sizeof (void *)) {
errno = EINVAL;
return -1;
}
((zmq_monitor_fn*) optval_) = monitor;
*optvallen_ = sizeof (void *);
return 0;
}
errno = EINVAL;