mirror of
https://github.com/zeromq/cppzmq.git
synced 2025-10-16 18:56:56 +02:00
Problem: poller's handler not aware of event type. (#200)
* Problem: Poller's handler not aware of event type. It was possible to register a handler for more than one event types but impossible to distinguish which event is being handled. Now events are passed to a handler. Besides that some other changes: * new test covering changes in the poller * modified existing tests to cover changes in the poller * defined handler_t in poller_t scope for more convinient use and simpler code * helper loopback binder to be re-used in tests * Problem: CMake build fails on Windows Issue #199 It seems that with GCC on Linux <array> is implicitly included by one of stl includes already in zmq.hpp but it breaks on Windows with Visual Studio. Adding explicit include for array. Can not verify right now but this change is a good practice so creating a pull request. * Poller: array include not between C++11 guards
This commit is contained in:

committed by
Luca Boccassi

parent
65475cb603
commit
1975818171
6
zmq.hpp
6
zmq.hpp
@@ -1020,7 +1020,9 @@ namespace zmq
|
||||
return *this;
|
||||
}
|
||||
|
||||
void add (zmq::socket_t &socket, short events, std::function<void(void)> &handler)
|
||||
using handler_t = std::function<void(short)>;
|
||||
|
||||
void add (zmq::socket_t &socket, short events, handler_t &handler)
|
||||
{
|
||||
if (0 == zmq_poller_add (poller_ptr, socket.ptr, handler ? &handler : NULL, events)) {
|
||||
poller_events.emplace_back (zmq_poller_event_t ());
|
||||
@@ -1044,7 +1046,7 @@ namespace zmq
|
||||
if (rc >= 0) {
|
||||
std::for_each (poller_events.begin (), poller_events.begin () + rc, [](zmq_poller_event_t& event) {
|
||||
if (event.user_data != NULL)
|
||||
(*reinterpret_cast<std::function<void(void)>*> (event.user_data)) ();
|
||||
(*reinterpret_cast<handler_t*> (event.user_data)) (event.events);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user