Commit 5ef63318 authored by Pieter Hintjens's avatar Pieter Hintjens

Merge pull request #341 from kennytm/master

Allow the ZMQ_MONITOR code compilable on gcc 4.7 on Linux.
parents 89d5054e c995de65
...@@ -456,7 +456,7 @@ Default value:: -1 (leave to OS default) ...@@ -456,7 +456,7 @@ Default value:: -1 (leave to OS default)
Applicable socket types:: all, when using TCP transports. Applicable socket types:: all, when using TCP transports.
ZMQ_MONITOR: Registers a callback for socket state changes ZMQ_MONITOR: Registers a callback for socket state changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Registers a callback function / event sink for changes in underlying socket state. Registers a callback function / event sink for changes in underlying socket state.
The default value of `NULL` means no monitor callback function. The default value of `NULL` means no monitor callback function.
......
...@@ -325,7 +325,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_, ...@@ -325,7 +325,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
monitor = ((zmq_monitor_fn*) optval_); monitor = *((zmq_monitor_fn**) &optval_);
return 0; return 0;
} }
} }
...@@ -550,8 +550,8 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_) ...@@ -550,8 +550,8 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
((zmq_monitor_fn*) optval_) = monitor; *((zmq_monitor_fn**) &optval_) = monitor;
*optvallen_ = sizeof (void *); *optvallen_ = sizeof (zmq_monitor_fn*);
return 0; return 0;
} }
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdarg.h>
#include "session_base.hpp" #include "session_base.hpp"
#include "socket_base.hpp" #include "socket_base.hpp"
#include "i_engine.hpp" #include "i_engine.hpp"
......
...@@ -99,16 +99,18 @@ int main (int argc, char *argv []) ...@@ -99,16 +99,18 @@ int main (int argc, char *argv [])
assert (rep); assert (rep);
// Expects failure - invalid size // Expects failure - invalid size
rc = zmq_setsockopt (rep, ZMQ_MONITOR, (void *)listening_sock_monitor, 20); zmq_monitor_fn *monitor;
monitor = listening_sock_monitor;
rc = zmq_setsockopt (rep, ZMQ_MONITOR, *(void **)&monitor, 20);
assert (rc == -1); assert (rc == -1);
assert (errno == EINVAL); assert (errno == EINVAL);
rc = zmq_setsockopt (rep, ZMQ_MONITOR, (void *)listening_sock_monitor, sizeof (void *)); rc = zmq_setsockopt (rep, ZMQ_MONITOR, *(void **)&monitor, sizeof (void *));
assert (rc == 0); assert (rc == 0);
void *monitor;
size_t sz = sizeof (void *); size_t sz = sizeof (void *);
rc = zmq_getsockopt (rep, ZMQ_MONITOR, monitor, &sz); rc = zmq_getsockopt (rep, ZMQ_MONITOR, &monitor, &sz);
assert (rc == 0); assert (rc == 0);
assert (monitor == listening_sock_monitor); assert (monitor == listening_sock_monitor);
...@@ -116,7 +118,7 @@ int main (int argc, char *argv []) ...@@ -116,7 +118,7 @@ int main (int argc, char *argv [])
rc = zmq_setsockopt (rep, ZMQ_MONITOR, NULL, 0); rc = zmq_setsockopt (rep, ZMQ_MONITOR, NULL, 0);
assert (rc == 0); assert (rc == 0);
rc = zmq_getsockopt (rep, ZMQ_MONITOR, monitor, &sz); rc = zmq_getsockopt (rep, ZMQ_MONITOR, &monitor, &sz);
assert (rc == 0); assert (rc == 0);
assert (monitor == listening_sock_monitor); assert (monitor == listening_sock_monitor);
...@@ -126,7 +128,8 @@ int main (int argc, char *argv []) ...@@ -126,7 +128,8 @@ int main (int argc, char *argv [])
void *req = zmq_socket (ctx, ZMQ_REQ); void *req = zmq_socket (ctx, ZMQ_REQ);
assert (req); assert (req);
rc = zmq_setsockopt (req, ZMQ_MONITOR, (void *)connecting_sock_monitor, sizeof (void *)); monitor = connecting_sock_monitor;
rc = zmq_setsockopt (req, ZMQ_MONITOR, *(void **)&monitor, sizeof (void *));
assert (rc == 0); assert (rc == 0);
rc = zmq_connect (req, "tcp://127.0.0.1:5560"); rc = zmq_connect (req, "tcp://127.0.0.1:5560");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment