|
4 år sedan | |
---|---|---|
.. | ||
cmake | 4 år sedan | |
demo | 4 år sedan | |
libzmq-pkg-config | 4 år sedan | |
tests | 4 år sedan | |
.clang-format | 4 år sedan | |
.gitignore | 4 år sedan | |
.travis.yml | 4 år sedan | |
CMakeLists.txt | 4 år sedan | |
LICENSE | 4 år sedan | |
README.md | 4 år sedan | |
appveyor.yml | 4 år sedan | |
ci_build.sh | 4 år sedan | |
cppzmqConfig.cmake.in | 4 år sedan | |
version.sh | 4 år sedan | |
zmq.hpp | 4 år sedan | |
zmq_addon.hpp | 4 år sedan |
cppzmq is a C++ binding for libzmq. It has the following design goals:
There are other C++ bindings for ZeroMQ with different design goals. In particular, none of the following bindings are header-only:
These examples require at least C++11.
#include <zmq.hpp>
int main()
{
zmq::context_t ctx;
zmq::socket_t sock(ctx, zmq::socket_type::push);
sock.bind("inproc://test");
sock.send(zmq::str_buffer("Hello, world"), zmq::send_flags::dontwait);
}
This a more complex example where we send and receive multi-part messages.
#include <iostream>
#include <zmq_addon.hpp>
int main()
{
zmq::context_t ctx;
zmq::socket_t sock1(ctx, zmq::socket_type::pair);
zmq::socket_t sock2(ctx, zmq::socket_type::pair);
sock1.bind("inproc://test");
sock2.connect("inproc://test");
std::array<zmq::const_buffer, 2> send_msgs = {
zmq::str_buffer("foo"),
zmq::str_buffer("bar!")
};
if (!zmq::send_multipart(sock1, send_msgs))
return 1;
std::vector<zmq::message_t> recv_msgs;
const auto ret = zmq::recv_multipart(
sock2, std::back_inserter(recv_msgs));
if (!ret)
return 1;
std::cout << "Got " << *ret
<< " messages" << std::endl;
return 0;
}
The users of cppzmq are expected to follow the guidelines below to ensure not to break when upgrading cppzmq to newer versions (non-exhaustive list):
The following macros may be used by consumers of cppzmq: CPPZMQ_VERSION
, CPPZMQ_VERSION_MAJOR
, CPPZMQ_VERSION_MINOR
, CPPZMQ_VERSION_PATCH
.
The contribution policy is at: http://rfc.zeromq.org/spec:22
Build steps:
Build libzmq via cmake. This does an out of source build and installs the build files
Build cppzmq via cmake. This does an out of source build and installs the build files
Using this:
A cmake find package scripts is provided for you to easily include this library. Add these lines in your CMakeLists.txt to include the headers and library files of cpp zmq (which will also include libzmq for you).
#find cppzmq wrapper, installed by make of cppzmq
find_package(cppzmq)
target_link_libraries(*Your Project Name* cppzmq)