zeromq / cppzmq

Header-only C++ binding for libzmq
http://www.zeromq.org
MIT License
1.97k stars 757 forks source link

zmq::multipart_t::send() only takes socket_t & argument, not socket_ref #448

Closed jeroenmuller closed 3 years ago

jeroenmuller commented 4 years ago

Using 4.8.0 with draft APIs enabled.

I am using the poller with zmq::multipart_t. The poller event gives me a socket_ref. However, multipart_t::send() only accepts a reference to a socket (not the socket_ref class). Therefore, I get a compiler error of this form:

src/mesh.cpp:36:29: error: cannot convert ‘zmq::socket_ref’ to ‘zmq::socket_t&’

An example of the code that leads to this issue (but I assume every case where we want to pass a socket_ref to multipart_t would lead to the same issue):

std::vector<zmq::poller_event<size_t>> events{10};
size_t num_events;
while ((num_events = d_in_poller.wait_all(events, std::chrono::milliseconds{0}))) {
    for (size_t i = 0; i != num_events; i++) {
        zmq::multipart_t multipart;
        multipart.recv(*(events[i].socket);
gummif commented 4 years ago

Good point. This can be easily fixed, you are welcome to submit a PR if you can.

gummif commented 4 years ago

An alternative is to use the recv_multipart and send_multipart functions.