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

* Add support for socket_ref to multipart_t ctor/send/recv

Fixes #448
This commit is contained in:
Dominic van Berkel 2021-04-27 16:41:21 +02:00 committed by GitHub
parent 545b12c56a
commit b65dde8725
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -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]")

View File

@ -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); }
@ -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;
@ -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;