Skip to content

Commit

Permalink
Add support for socket_ref to multipart_t ctor/send/recv (#487)
Browse files Browse the repository at this point in the history
* Add support for socket_ref to multipart_t ctor/send/recv

Fixes #448
  • Loading branch information
barometz committed Apr 27, 2021
1 parent 545b12c commit b65dde8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
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

0 comments on commit b65dde8

Please sign in to comment.