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

Feat/monitor poll #414

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions tests/monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,24 @@ TEST_CASE("monitor init get event count", "[monitor]")
}
}

SECTION("poller_t get_event")
{
zmq::poller_t<> poller;
CHECK_NOTHROW(poller.add(monitor, zmq::event_flags::pollin));

while (total < expected_event_count)
{
std::vector<zmq::poller_event<>> events(1);
if(0 == poller.wait_all(events, std::chrono::milliseconds{ 100 }))
continue;

CHECK(zmq::event_flags::pollin == events[0].events);
CHECK(monitor.get_event(eventMsg, address));

lbd_count_event(eventMsg);
}
}

CHECK(connect_delayed == 1);
CHECK(connected == 1);
CHECK(total == expected_event_count);
Expand Down
2 changes: 2 additions & 0 deletions zmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2232,6 +2232,8 @@ class monitor_t

ZMQ_NODISCARD const void *handle() const ZMQ_NOTHROW { return _monitor_socket.handle(); }

operator socket_ref() ZMQ_NOTHROW { return (zmq::socket_ref) _monitor_socket; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I'd not add an operator here but rather a named socket() member function. Actually, then the handle/socket_handle function is not necessary at all, since its handle can be accessed through the socket_ref.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.


#if ZMQ_VERSION_MAJOR >= 4
bool get_event(zmq_event_t& eventMsg, std::string& address, zmq::recv_flags flags = zmq::recv_flags::none)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about the signature of this method. What about

std::optional<std::pair<zmq_event_t, std::string>> get_event(zmq::recv_flags flags = zmq::recv_flags::none)

(This requires C++17 this way, but we can also do this with the fallback to detail::trivial_optional as done for other types)

This removes the ambiguity of whether the original value of eventMsg and address are used and in what cases they are modified.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'm not very familiar with std::optional and will try to implement this way

{
Expand Down