libuv
is here, with uvw
it's just a matter of invoking a member function rather than a free function
libuv
nor uvw
, so it's up to you
auto loop = uvw::Loop::getDefault();
auto poller = loop->resource<uvw::PollHandle>(fd);
poller->on<uvw::PollEvent>(
[](const auto &, auto &req)
{
std::cout << "poller - some event?\n";
});
if(poller->init())
{
std::cout << "poller - initialized?\n";
poller->start(uvw::PollHandle::Event::READABLE);
}
else
{
std::cerr << "poller - error?\n";
}
loop->run();
uvw
is a layer on top of libuv
and makes you available what is exposed by the underlying library
Hi folks, I have a question about best practices and design choices
I've written up a small mDNS library with service discovery and querying being the key use cases. I using uvw which means I don't have to deal with sockets and can get a good set of platform agnostic APIs like ntohs
etc. My question is what is the best way to post callbacks given that everything is async. e.g
I have the following API which performs a discovery query and the API accepts callbacks
void discover(discovery_response_f fn,
std::function<void(const uvw::ErrorEvent&)> error_fn);
where discovery_response_f
is a client supplied function pointer which receives a parsed response. In the implementation, those are called in the listeners for UDPDataEvent
and ErrorEvent
. I'm wondering if the more idiomatic way would be have my classes inherit from Emitter and provide similar Events that client can listen on. Looking at uvw, its obvious it would need a good dose of template wizardry, but I'm just what would others recommend ? No rush here. Just looking for wisdom :)