Skip to content

Commit 9a655c1

Browse files
authored
Merge pull request zeromq#595 from uyha/poller-fd
add function for adding file descriptor to poller_t
2 parents 2e6eff0 + 36b6053 commit 9a655c1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

zmq.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,6 +2663,17 @@ template<typename T = no_user_data> class poller_t
26632663
add_impl(socket, events, nullptr);
26642664
}
26652665

2666+
template<
2667+
typename Dummy = void,
2668+
typename =
2669+
typename std::enable_if<!std::is_same<T, no_user_data>::value, Dummy>::type>
2670+
void add(fd_t fd, event_flags events, T *user_data)
2671+
{
2672+
add_impl(fd, events, user_data);
2673+
}
2674+
2675+
void add(fd_t fd, event_flags events) { add_impl(fd, events, nullptr); }
2676+
26662677
void remove(zmq::socket_ref socket)
26672678
{
26682679
if (0 != zmq_poller_remove(poller_ptr.get(), socket.handle())) {
@@ -2729,6 +2740,15 @@ template<typename T = no_user_data> class poller_t
27292740
throw error_t();
27302741
}
27312742
}
2743+
2744+
void add_impl(fd_t fd, event_flags events, T *user_data)
2745+
{
2746+
if (0
2747+
!= zmq_poller_add_fd(poller_ptr.get(), fd, user_data,
2748+
static_cast<short>(events))) {
2749+
throw error_t();
2750+
}
2751+
}
27322752
};
27332753
#endif // defined(ZMQ_BUILD_DRAFT_API) && defined(ZMQ_CPP11) && defined(ZMQ_HAVE_POLLER)
27342754

0 commit comments

Comments
 (0)