Skip to content

Commit

Permalink
added missing data field
Browse files Browse the repository at this point in the history
  • Loading branch information
burilovmv committed Jul 8, 2017
1 parent 0ad0978 commit c5d527f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/zmq.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ ZMQ_EXPORT void zmq_version (int *major, int *minor, int *patch);

/* Error handler callback */
typedef void(*zmq_error_fn) (int err, const char* host, void* data);
ZMQ_EXPORT int zmq_error_handler(void* context, zmq_error_fn ffn);
ZMQ_EXPORT int zmq_error_handler(void* context, zmq_error_fn ffn, void* data);

/******************************************************************************/
/* 0MQ infrastructure (a.k.a. context) initialisation & termination. */
Expand Down
11 changes: 9 additions & 2 deletions src/ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ int clipped_maxsocket (int max_requested)
zmq::ctx_t::ctx_t () :
tag (ZMQ_CTX_TAG_VALUE_GOOD),
error_fn(0),
error_data(0),
starting (true),
terminating (false),
reaper (NULL),
Expand Down Expand Up @@ -108,16 +109,17 @@ bool zmq::ctx_t::check_tag ()
return tag == ZMQ_CTX_TAG_VALUE_GOOD;
}

void zmq::ctx_t::set_error_handler(zmq_error_fn ffn)
void zmq::ctx_t::set_error_handler(zmq_error_fn ffn, void* data)
{
error_fn = ffn;
error_data = data;
}

void zmq::ctx_t::handle_error(int errno_, const char* host)
{
if(error_fn)
{
error_fn(errno_, host, NULL);
error_fn(errno_, host, error_data);
}
}

Expand Down Expand Up @@ -151,6 +153,11 @@ zmq::ctx_t::~ctx_t ()
randombytes_close ();
#endif

if(error_data)
{
free(error_data);
}

// Remove the tag, so that the object is considered dead.
tag = ZMQ_CTX_TAG_VALUE_BAD;
}
Expand Down
3 changes: 2 additions & 1 deletion src/ctx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace zmq
bool check_tag ();

// set error handler callback
void set_error_handler(zmq_error_fn ffn);
void set_error_handler(zmq_error_fn ffn, void* data);

// redirects error to error handler callback if it is set
void handle_error(int errno_, const char* host);
Expand Down Expand Up @@ -153,6 +153,7 @@ namespace zmq

// Error handler callback
zmq_error_fn error_fn;
void* error_data;

// Sockets belonging to this context. We need the list so that
// we can notify the sockets when zmq_ctx_term() is called.
Expand Down
4 changes: 2 additions & 2 deletions src/zmq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ int zmq_errno (void)
}


int zmq_error_handler(void* ctx_, zmq_error_fn ffn)
int zmq_error_handler(void* ctx_, zmq_error_fn ffn, void* data)
{
if (!ctx_ || !((zmq::ctx_t *) ctx_)->check_tag()) {
errno = EFAULT;
return -1;
}

((zmq::ctx_t *) ctx_)->set_error_handler(ffn);
((zmq::ctx_t *) ctx_)->set_error_handler(ffn, data);

return 0;
}
Expand Down

0 comments on commit c5d527f

Please sign in to comment.