Useful ZMQ Message Helper Classes

If you use ZMQ in C/C++, be sure to check this out.

Why use this, u say?The advantage is that msg_single_t/msg_multi_t objects on the stack get cleaned up automatically. It helps to clean up a lot of boilerplate code.


zmq_msg_t msg; 
zmq_msg_init_size(&msg, sizeof(int)); 
int payload = zmq_msg_recv(&msg, zpipe, 0); 

Can now be replaced by

msg_single_t msg(sizeof(int)); 
int payload = msg.recv(zpipe, 0); 

Closing the msg is done for you when msg goes out of scope. This helps to reduce memory leaks / zmq errors due to not closing the message properly. Pretty, pretty code!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s