• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/workflows/H19-Sep-2021-196181

cmake/H19-Sep-2021-96

demo/H03-May-2022-86

examples/H03-May-2022-14494

libzmq-pkg-config/H03-May-2022-3427

tests/H03-May-2022-3,2732,783

.clang-formatH A D19-Sep-20211.4 KiB5450

.gitignoreH A D19-Sep-202149 64

LICENSEH A D19-Sep-20211.1 KiB1815

README.mdH A D19-Sep-20215.7 KiB135110

cppzmqConfig.cmake.inH A D19-Sep-2021957 3730

version.shH A D19-Sep-2021721 2215

zmq.hppH A D19-Sep-202176.6 KiB2,7112,290

zmq_addon.hppH A D19-Sep-202123.6 KiB754498

README.md

1[![CI](https://github.com/zeromq/cppzmq/actions/workflows/ci.yml/badge.svg)](https://github.com/zeromq/cppzmq/actions)
2[![Coverage Status](https://coveralls.io/repos/github/zeromq/cppzmq/badge.svg?branch=master)](https://coveralls.io/github/zeromq/cppzmq?branch=master)
3[![License](https://img.shields.io/github/license/zeromq/cppzmq.svg)](https://github.com/zeromq/cppzmq/blob/master/LICENSE)
4
5Introduction & Design Goals
6===========================
7
8cppzmq is a C++ binding for libzmq. It has the following design goals:
9 - cppzmq maps the libzmq C API to C++ concepts. In particular:
10   - it is type-safe (the libzmq C API exposes various class-like concepts as void*)
11   - it provides exception-based error handling (the libzmq C API provides errno-based error handling)
12   - it provides RAII-style classes that automate resource management (the libzmq C API requires the user to take care to free resources explicitly)
13 - cppzmq is a light-weight, header-only binding. You only need to include the header file zmq.hpp (and maybe zmq_addon.hpp) to use it.
14 - zmq.hpp is meant to contain direct mappings of the abstractions provided by the libzmq C API, while zmq_addon.hpp provides additional higher-level abstractions.
15
16There are other C++ bindings for ZeroMQ with different design goals. In particular, none of the following bindings are header-only:
17 - [zmqpp](https://github.com/zeromq/zmqpp) is a high-level binding to libzmq.
18 - [czmqpp](https://github.com/zeromq/czmqpp) is a binding based on the high-level czmq API.
19 - [fbzmq](https://github.com/facebook/fbzmq) is a binding that integrates with Apache Thrift and provides higher-level abstractions in addition. It requires C++14.
20
21Supported platforms
22===================
23
24 - Only a subset of the platforms that are supported by libzmq itself are supported. Some features already require a compiler supporting C++11. In the future, probably all features will require C++11. To build and run the tests, CMake and Catch are required.
25 - Any libzmq 4.x version is expected to work. DRAFT features may only work for the most recent tested version. Currently explicitly tested libzmq versions are
26   - 4.2.0 (without DRAFT API)
27   - 4.3.4 (with and without DRAFT API)
28 - Platforms with full support (i.e. CI executing build and tests)
29   - Ubuntu 18.04 x64 (with gcc 4.8.5, 5.5.0, 7.5.0)
30   - Ubuntu 20.04 x64 (with gcc 9.3.0, 10.3.0 and clang 12)
31   - Visual Studio 2017 x64
32   - Visual Studio 2019 x64
33   - macOS 10.15 (with clang 12, without DRAFT API)
34 - Additional platforms that are known to work:
35   - We have no current reports on additional platforms that are known to work yet. Please add your platform here. If CI can be provided for them with a cloud-based CI service working with GitHub, you are invited to add CI, and make it possible to be included in the list above.
36 - Additional platforms that probably work:
37   - Any platform supported by libzmq that provides a sufficiently recent gcc (4.8.1 or newer) or clang (3.4.1 or newer)
38   - Visual Studio 2012+ x86/x64
39
40Examples
41========
42These examples require at least C++11.
43```c++
44#include <zmq.hpp>
45
46int main()
47{
48    zmq::context_t ctx;
49    zmq::socket_t sock(ctx, zmq::socket_type::push);
50    sock.bind("inproc://test");
51    sock.send(zmq::str_buffer("Hello, world"), zmq::send_flags::dontwait);
52}
53```
54This a more complex example where we send and receive multi-part messages over TCP with a wildcard port.
55```c++
56#include <iostream>
57#include <zmq_addon.hpp>
58
59int main()
60{
61    zmq::context_t ctx;
62    zmq::socket_t sock1(ctx, zmq::socket_type::push);
63    zmq::socket_t sock2(ctx, zmq::socket_type::pull);
64    sock1.bind("tcp://127.0.0.1:*");
65    const std::string last_endpoint =
66        sock1.get(zmq::sockopt::last_endpoint);
67    std::cout << "Connecting to "
68              << last_endpoint << std::endl;
69    sock2.connect(last_endpoint);
70
71    std::array<zmq::const_buffer, 2> send_msgs = {
72        zmq::str_buffer("foo"),
73        zmq::str_buffer("bar!")
74    };
75    if (!zmq::send_multipart(sock1, send_msgs))
76        return 1;
77
78    std::vector<zmq::message_t> recv_msgs;
79    const auto ret = zmq::recv_multipart(
80        sock2, std::back_inserter(recv_msgs));
81    if (!ret)
82        return 1;
83    std::cout << "Got " << *ret
84              << " messages" << std::endl;
85    return 0;
86}
87```
88
89See the `examples` directory for more examples. When the project is compiled with tests enabled, each example gets compiled to an executable.
90
91Compatibility Guidelines
92========================
93
94The users of cppzmq are expected to follow the guidelines below to ensure not to break when upgrading cppzmq to newer versions (non-exhaustive list):
95
96* Do not depend on any macros defined in cppzmq unless explicitly declared public here.
97
98The following macros may be used by consumers of cppzmq: `CPPZMQ_VERSION`, `CPPZMQ_VERSION_MAJOR`, `CPPZMQ_VERSION_MINOR`, `CPPZMQ_VERSION_PATCH`.
99
100Contribution policy
101===================
102
103The contribution policy is at: http://rfc.zeromq.org/spec:22
104
105Build instructions
106==================
107
108Build steps:
109
1101. Build [libzmq](https://github.com/zeromq/libzmq) via cmake. This does an out of source build and installs the build files
111   - download and unzip the lib, cd to directory
112   - mkdir build
113   - cd build
114   - cmake ..
115   - sudo make -j4 install
116
1172. Build cppzmq via cmake. This does an out of source build and installs the build files
118   - download and unzip the lib, cd to directory
119   - mkdir build
120   - cd build
121   - cmake ..
122   - sudo make -j4 install
123
124Using this:
125
126A cmake find package scripts is provided for you to easily include this library.
127Add these lines in your CMakeLists.txt to include the headers and library files of
128cpp zmq (which will also include libzmq for you).
129
130```
131#find cppzmq wrapper, installed by make of cppzmq
132find_package(cppzmq)
133target_link_libraries(*Your Project Name* cppzmq)
134```
135