Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for socket_ref to multipart_t ctor/send/recv #487

Merged
merged 4 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/multipart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
#include <zmq_addon.hpp>

#ifdef ZMQ_HAS_RVALUE_REFS

#ifdef ZMQ_CPP17
static_assert(std::is_invocable<decltype(&zmq::multipart_t::send),
zmq::multipart_t *,
zmq::socket_ref,
int>::value,
"Can't multipart_t::send with socket_ref");
static_assert(std::is_invocable<decltype(&zmq::multipart_t::recv),
zmq::multipart_t *,
zmq::socket_ref,
int>::value,
"Can't multipart_t::recv with socket_ref");
#endif
static_assert(std::is_constructible<zmq::multipart_t, zmq::socket_ref>::value,
"Can't construct with socket_ref");

/// \todo split this up into separate test cases
///
TEST_CASE("multipart legacy test", "[multipart]")
Expand Down
6 changes: 3 additions & 3 deletions zmq_addon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class multipart_t
multipart_t() {}

// Construct from socket receive
multipart_t(socket_t &socket) { recv(socket); }
multipart_t(socket_ref socket) { recv(socket); }

// Construct from memory block
multipart_t(const void *src, size_t size) { addmem(src, size); }
Expand Down Expand Up @@ -393,7 +393,7 @@ class multipart_t
bool empty() const { return m_parts.empty(); }

// Receive multipart message from socket
bool recv(socket_t &socket, int flags = 0)
bool recv(socket_ref socket, int flags = 0)
{
clear();
bool more = true;
Expand All @@ -413,7 +413,7 @@ class multipart_t
}

// Send multipart message to socket
bool send(socket_t &socket, int flags = 0)
bool send(socket_ref socket, int flags = 0)
{
flags &= ~(ZMQ_SNDMORE);
bool more = size() > 0;
Expand Down