mirror of
https://github.com/matrix-construct/construct
synced 2024-06-02 18:18:56 +02:00
ircd::net::dns::resolver: Split recv into function from work loop.
This commit is contained in:
parent
749647bb89
commit
27d0c25f9b
|
@ -67,6 +67,7 @@ struct ircd::net::dns::resolver
|
|||
void handle_reply(const header &, const const_buffer &body, tag &);
|
||||
void handle_reply(const ipport &, const header &, const const_buffer &body);
|
||||
void handle(const ipport &, const mutable_buffer &);
|
||||
std::tuple<net::ipport, mutable_buffer> recv_recv(const mutable_buffer &);
|
||||
void recv_worker();
|
||||
ctx::context recv_context;
|
||||
|
||||
|
|
|
@ -494,34 +494,11 @@ try
|
|||
64_KiB
|
||||
};
|
||||
|
||||
const auto interruption{[this]
|
||||
(ctx::ctx *const &)
|
||||
{
|
||||
if(this->ns.is_open())
|
||||
this->ns.cancel();
|
||||
}};
|
||||
|
||||
const asio::mutable_buffers_1 bufs{buf};
|
||||
ip::udp::endpoint ep;
|
||||
while(ns.is_open()) try
|
||||
{
|
||||
size_t recv; continuation
|
||||
const auto &[from, reply]
|
||||
{
|
||||
continuation::asio_predicate, interruption, [this, &bufs, &recv, &ep]
|
||||
(auto &yield)
|
||||
{
|
||||
recv = ns.async_receive_from(bufs, ep, yield);
|
||||
}
|
||||
};
|
||||
|
||||
const mutable_buffer &reply
|
||||
{
|
||||
data(buf), recv
|
||||
};
|
||||
|
||||
const net::ipport &from
|
||||
{
|
||||
make_ipport(ep)
|
||||
recv_recv(buf)
|
||||
};
|
||||
|
||||
handle(from, reply);
|
||||
|
@ -546,6 +523,40 @@ catch(const std::exception &e)
|
|||
};
|
||||
}
|
||||
|
||||
std::tuple<ircd::net::ipport, ircd::mutable_buffer>
|
||||
ircd::net::dns::resolver::recv_recv(const mutable_buffer &buf)
|
||||
{
|
||||
const asio::mutable_buffers_1 bufs
|
||||
{
|
||||
buf
|
||||
};
|
||||
|
||||
const auto interruption{[this](ctx::ctx *const &)
|
||||
{
|
||||
if(this->ns.is_open())
|
||||
this->ns.cancel();
|
||||
}};
|
||||
|
||||
ip::udp::endpoint ep;
|
||||
size_t recv; continuation
|
||||
{
|
||||
continuation::asio_predicate, interruption, [this, &bufs, &recv, &ep]
|
||||
(auto &yield)
|
||||
{
|
||||
recv = ns.async_receive_from(bufs, ep, yield);
|
||||
}
|
||||
};
|
||||
|
||||
return
|
||||
{
|
||||
make_ipport(ep),
|
||||
mutable_buffer
|
||||
{
|
||||
data(buf), recv
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void
|
||||
ircd::net::dns::resolver::handle(const ipport &from,
|
||||
const mutable_buffer &buf)
|
||||
|
|
Loading…
Reference in a new issue