From f8b9ca5f420a4d8a46aa8fd789f51fe5594cccf4 Mon Sep 17 00:00:00 2001 From: Pieter Hintjens Date: Mon, 21 Dec 2015 10:56:37 +0100 Subject: [PATCH] Problem: zmq timers API is not CLASS conformant If we're going to add CLASS-like APIs we should use the proper syntax; specifically 'destroy' instead of 'close', which is a hangover from the 'ZeroMQ is like sockets' model we're slowly moving away from. Solution: change zmq_timers_close(p) to zmq_timers_destroy(&p) --- include/zmq.h | 4 ++-- src/zmq.cpp | 9 +++++---- tests/test_timers.cpp | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/zmq.h b/include/zmq.h index 88525bd8..0819beed 100644 --- a/include/zmq.h +++ b/include/zmq.h @@ -457,8 +457,8 @@ ZMQ_EXPORT int zmq_poller_remove_fd (void *poller, int fd); typedef void (zmq_timer_fn)(int timer_id, void *arg); -ZMQ_EXPORT void *zmq_timers_new (); -ZMQ_EXPORT int zmq_timers_close (void *timers); +ZMQ_EXPORT void *zmq_timers_new (void); +ZMQ_EXPORT int zmq_timers_destroy (void **timers); ZMQ_EXPORT int zmq_timers_add (void *timers, size_t interval, zmq_timer_fn handler, void *arg); ZMQ_EXPORT int zmq_timers_cancel (void *timers, int timer_id); ZMQ_EXPORT int zmq_timers_set_interval (void *timers, int timer_id, size_t interval); diff --git a/src/zmq.cpp b/src/zmq.cpp index 63af37e9..dd4d36ca 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -1185,14 +1185,15 @@ void *zmq_timers_new () return timers; } -int zmq_timers_close (void *timers_) +int zmq_timers_destroy (void **timers_p_) { - if (!timers_ || !((zmq::timers_t*)timers_)->check_tag ()) { + void *timers = *timers_p_; + if (!timers || !((zmq::timers_t *) timers)->check_tag ()) { errno = EFAULT; return -1; } - - delete ((zmq::timers_t*)timers_); + delete ((zmq::timers_t *) timers); + *timers_p_ = NULL; return 0; } diff --git a/tests/test_timers.cpp b/tests/test_timers.cpp index ee70367f..3c9b6575 100644 --- a/tests/test_timers.cpp +++ b/tests/test_timers.cpp @@ -119,7 +119,7 @@ int main (void) assert (rc == 0); assert (!timer_invoked); - rc = zmq_timers_close (timers); + rc = zmq_timers_destroy (&timers); assert (rc == 0); return 0;