mirror of
https://github.com/zeromq/libzmq.git
synced 2025-01-03 03:45:43 +08:00
Fix monitor_event() to work at all.
There are three versions of monitor_event(), all taking variadic arguments. The original code just has the first one creating a va_list and passing that va_list variadically to the second one... which creates a new va_list and passes it variadically to the third one... and of course everything blows up when we try to pull a non-va_list argument off the stack. The correct approach matches the C standard library's use of printf/vprintf, scanf/vscanf, and so on. Once you make a va_list, you must pass it only to functions which expect a va_list parameter.
This commit is contained in:
parent
537a802788
commit
7fadd708a0
10
src/ctx.cpp
10
src/ctx.cpp
@ -353,7 +353,15 @@ zmq::endpoint_t zmq::ctx_t::find_endpoint (const char *addr_)
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
void zmq::ctx_t::monitor_event (zmq::socket_base_t *socket_, int event_, va_list args_)
|
||||
void zmq::ctx_t::monitor_event (zmq::socket_base_t *socket_, int event_, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (event_, args);
|
||||
va_monitor_event (socket_, event_, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
void zmq::ctx_t::va_monitor_event (zmq::socket_base_t *socket_, int event_, va_list args_)
|
||||
{
|
||||
if (monitor_fn != NULL) {
|
||||
zmq_event_data_t data;
|
||||
|
@ -97,7 +97,8 @@ namespace zmq
|
||||
|
||||
// Monitoring specific
|
||||
int monitor (zmq_monitor_fn *monitor_);
|
||||
void monitor_event (zmq::socket_base_t *socket_, int event_, va_list args_);
|
||||
void monitor_event (zmq::socket_base_t *socket_, int event_, ...);
|
||||
void va_monitor_event (zmq::socket_base_t *socket_, int event_, va_list args_);
|
||||
|
||||
enum {
|
||||
term_tid = 0,
|
||||
|
@ -290,10 +290,15 @@ void zmq::session_base_t::monitor_event (int event_, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, event_);
|
||||
socket->monitor_event (event_, args);
|
||||
va_monitor_event (event_, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
void zmq::session_base_t::va_monitor_event (int event_, va_list args)
|
||||
{
|
||||
socket->va_monitor_event (event_, args);
|
||||
}
|
||||
|
||||
void zmq::session_base_t::process_plug ()
|
||||
{
|
||||
if (connect)
|
||||
|
@ -24,6 +24,7 @@
|
||||
#define __ZMQ_SESSION_BASE_HPP_INCLUDED__
|
||||
|
||||
#include <string>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "own.hpp"
|
||||
#include "io_object.hpp"
|
||||
@ -67,6 +68,7 @@ namespace zmq
|
||||
void terminated (zmq::pipe_t *pipe_);
|
||||
|
||||
void monitor_event (int event_, ...);
|
||||
void va_monitor_event (int event_, va_list args);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -1001,6 +1001,11 @@ void zmq::socket_base_t::monitor_event (int event_, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, event_);
|
||||
get_ctx ()->monitor_event (this, event_, args);
|
||||
va_monitor_event(event, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
void zmq::socket_base_t::monitor_event (int event_, va_list args)
|
||||
{
|
||||
get_ctx ()->va_monitor_event (this, event_, args);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "own.hpp"
|
||||
#include "array.hpp"
|
||||
@ -102,6 +103,7 @@ namespace zmq
|
||||
void unlock();
|
||||
|
||||
void monitor_event (int event_, ...);
|
||||
void va_monitor_event (int event_, va_list args);
|
||||
|
||||
protected:
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user