mirror of
https://gitlab.com/niansa/libcrosscoro.git
synced 2025-03-06 20:53:32 +01:00
* udp_peer! I hope using the udp peer makes sense on how udp packets are sent and received now. Time will tell! * Fix broken benchmark tcp server listening race condition
43 lines
No EOL
1.1 KiB
C++
43 lines
No EOL
1.1 KiB
C++
#include "catch.hpp"
|
|
|
|
#include <coro/coro.hpp>
|
|
|
|
#include <chrono>
|
|
|
|
TEST_CASE("dns_resolver basic")
|
|
{
|
|
coro::io_scheduler scheduler{
|
|
coro::io_scheduler::options{.thread_strategy = coro::io_scheduler::thread_strategy_t::spawn}
|
|
};
|
|
|
|
coro::net::dns_resolver dns_resolver{scheduler, std::chrono::milliseconds{5000}};
|
|
|
|
std::atomic<bool> done{false};
|
|
|
|
auto make_host_by_name_task = [&](coro::net::hostname hn) -> coro::task<void>
|
|
{
|
|
auto result_ptr = co_await std::move(dns_resolver.host_by_name(hn));
|
|
|
|
if(result_ptr->status() == coro::net::dns_status::complete)
|
|
{
|
|
for(const auto& ip_addr : result_ptr->ip_addresses())
|
|
{
|
|
std::cerr << coro::net::to_string(ip_addr.domain()) << " " << ip_addr.to_string() << "\n";
|
|
}
|
|
}
|
|
|
|
done = true;
|
|
|
|
co_return;
|
|
};
|
|
|
|
scheduler.schedule(make_host_by_name_task(coro::net::hostname{"www.example.com"}));
|
|
|
|
while(!done)
|
|
{
|
|
std::this_thread::sleep_for(std::chrono::milliseconds{10});
|
|
}
|
|
|
|
scheduler.shutdown();
|
|
REQUIRE(scheduler.empty());
|
|
} |