This commit fixes a regression introduced in a3e5b54c3 (Problem: Socket
options lack type-safety (#393)).
It addresses the following error reported when building the project
on macOS 10.11.6.
Errors like the following:
cppzmq/zmq.hpp:1325:39: error: default initialization of an object of const type 'const affinity_t' (aka 'const integral_option<4, unsigned long long, false>') without a user-provided default constructor
Compiler version:
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Similar issues:
* https://github.com/tensorflow/tensorflow/issues/28839
error: default initialization of an object of const type 'const Subgraph::Identity' without a user-provided default constructor
* https://bugzilla.mozilla.org/show_bug.cgi?id=1451088
Clang 3.8: error: default initialization of an object of const type 'const js::jit::ArithPolicy' without a user-provided default constructor
* https://github.com/googleapis/google-cloud-cpp/issues/1593
[osx] error: default initialization of an object of const type
Co-authored-by: Gudmundur Adalsteinsson <ofpgummi@yahoo.com>
Solution: Implement a type for each socket option.
Each option has an associated type, therefore they
can't be simply defined as an enum class.
Use new sockopt getter in test util
Add socket option get function for strings and tests
* Problem: Macros not defined in older versions
Solution: Guard usage of libzmq macros
* Test older version of libzmq with C++11 or later
* Use a slightly newer libzmq version
Solution: Define an enum class for the context options
Co-Authored-By: Simon Giesecke <simon.giesecke@gmail.com>
Co-authored-by: Simon Giesecke <simon.giesecke@gmail.com>
Solution: Add shutdown(). This function is required
for clean termination of the zmq context in multi-threaded
applications where sockets are used in threads. In particular
if blocking operation are used and if sockets can be created
at any time.
* Improve tests and documentation
For some reason that I didn't get to the root cause, gcc 4.8.1 (that I'm
stuck with) does not like the initializer for `unique_ptr` implemented
as a lambda:
```
third_party/zmqcpp/repo/zmq.hpp: In constructor 'zmq::poller_t<T>::poller_t() [with T = std::function<void(zmq::event_flags)>]':
third_party/zmqcpp/repo/zmq.hpp:1871:5: error: converting to 'std::unique_ptr<void, zmq::poller_t<std::function<void(zmq::event_flags)> >::destroy_poller_t>' from initializer list would use explicit constructor 'std::unique_ptr<_Ty, _Dx>::unique_ptr(std::unique_ptr<_Ty, _Dx>::pointer) [with _Ty = void; _Dx = zmq::poller_t<std::function<void(zmq::event_flags)> >::destroy_poller_t; std::unique_ptr<_Ty, _Dx>::pointer = void*]'
poller_t() = default;
^
In file included from networking/ipc/ipc.cc:6:0:
third_party/zmqcpp/repo/zmq_addon.hpp: At global scope:
third_party/zmqcpp/repo/zmq_addon.hpp:447:40: note: synthesized method 'zmq::poller_t<T>::poller_t() [with T = std::function<void(zmq::event_flags)>]' first required here
poller_t<handler_type> base_poller{};
^
In file included from ./networking/ipc/ipc.h:13:0,
from networking/ipc/ipc.cc:1:
third_party/zmqcpp/repo/zmq.hpp: In constructor 'zmq::poller_t<T>::poller_t() [with T = zmq::socket_t]':
third_party/zmqcpp/repo/zmq.hpp:1871:5: error: converting to 'std::unique_ptr<void, zmq::poller_t<zmq::socket_t>::destroy_poller_t>' from initializer list would use explicit constructor 'std::unique_ptr<_Ty, _Dx>::unique_ptr(std::unique_ptr<_Ty, _Dx>::pointer) [with _Ty = void; _Dx = zmq::poller_t<zmq::socket_t>::destroy_poller_t; std::unique_ptr<_Ty, _Dx>::pointer = void*]'
poller_t() = default;
^
networking/ipc/ipc.cc: In member function 'void networking::ipc::Ipc::ThreadMain()':
networking/ipc/ipc.cc:313:36: note: synthesized method 'zmq::poller_t<T>::poller_t() [with T = zmq::socket_t]' first required here
::zmq::poller_t<::zmq::socket_t> poller;
^
```
This moves the initialization to constructor, and makes gcc happy.
This to avoid the following warning with the '-Wold-style-cast' flag enabled :
./zmq.hpp:763:29: warning: use of old-style cast [-Wold-style-cast]
return (size_t) nbytes;
^
./zmq.hpp: In member function ‘size_t zmq::socket_t::recv(void*, size_t, int)’:
./zmq.hpp:793:29: warning: use of old-style cast [-Wold-style-cast]
return (size_t) nbytes;
Solution: Implement for socket_t, context_t, message_t and poller_t
Additionally remove dependency on <functional> by refactoring poller_t
and remove unused <unordered_map> include.
Currently cppzmq as relatively simple and header only library depends on rather
complex unit test framework googletest.
Current issues:
- Googletest requires downloading and building it every time on travis
as cache support is limited there
- Googletest build is signifficant with comparison to cppzmq unittests
total runtime
Solution: Port existing tests to Catch - header only C++ framework and
gain ~20% build speed up on travis.
Why Catch?
It is well know C++ header only testing framework. It works well, it is
being kept up to date and maintainers seem to pay attention to
community's comments and issues.
We can not use Catch2 currently as we still support pre-C++11 compilers.
This commit introduces new socket_type enumeration values as well
as the following supporting functions:
socket_t::join()
socket_t::leave()
message_t::group()
message_t::set_group()
For header only library like cppzmq, whitespace style inherited from
libzmq is too restrictive.
Solution: relaxing whitespace before parens from always to in control
statements only, increased max column width from 80 to 85 and removing
requirement of whitespace after template keyword.
Solution: Constructor logic moved to the same place where cleanup is and
marking constructor `default`. Init/cleanup code is in one pleace making
it easier to read/maintain.
Latest modification to the poller made move constructor and move
assigment operator not complete. In order to prevent that in the future
poller should be default movable. Unique pointer has been used to
manager zmq_poller. That makes code simpler and safer now.
* Problem: poller can segfault when modified from registred handler.
It is possible that a user would like to add/remove sockets from
handlers. As handlers and poll items might be removed while not
being processed yet - we have a segfault situation.
Provided unit test `remove_from_handler` demonstrates the problem.
Solution: Modify internal poll item data structure only after processing
of events is finished.
Please not that events processing path performance remains the same when there are
no modification (add/remove) to the poller (no rebuild) - main real use case.
As an effect of changes `size()` method has been removed as it does not
represent any meaningful information anymore. There are active and pending
(waiting for rebuild) poll items so two different sizes. User can
easily track on their side number of registered sockets if original size
information is needed.
`wait` method returns number of processed sockets now. It might be
useful information to a user for no extra cost.
We have a deprecated method `add` in poller that contradicts purpose of a draft
API where it can change without deprecation period.
Solution: remove the method so we do not to maintain it anymore.
Solution: Added `modify` method based on `zmq_poller_modify` and test cases
covering it.
Reduced code duplication in existing test cases by introducing
`client_server_setup` helper struct.
Issue is reproducible in deprecated add method with empty handler
followed by wait that kicks in (covered by provided unit test).
I would prefer we remove this method completely as maintaining something
that we consider `deprecated` is unnecessary in `draft` API.