TeaSpeak-Client/native/dns/test/main.cpp

52 lines
1.2 KiB
C++
Raw Normal View History

2019-10-24 12:41:35 -04:00
#include <iostream>
#include <event2/thread.h>
#include <cstring>
#include <variant>
#include <random>
#include <deque>
#include <cassert>
#include <unbound-event.h>
#include "../src/response.h"
#include "../src/resolver.h"
#include "../utils.h"
using namespace tc::dns;
using namespace std;
namespace parser = response::rrparser;
int main() {
evthread_use_pthreads();
//evthread_enable_lock_debugging();
std::string error{};
Resolver resolver{};
if(!resolver.initialize(error, true, true)) {
cerr << "failed to initialize resolver: " << error << endl;
return 1;
}
auto begin = chrono::system_clock::now();
for(int i = 0; i < 250; i++) {
cr(resolver, {
to_string(i) + "ts.twerion.net",
9922
}, [begin](bool success, auto data) {
auto end = chrono::system_clock::now();
cout << "Success: " << success << " Time: " << chrono::ceil<chrono::milliseconds>(end - begin).count() << "ms" << endl;
if(success) {
auto address = std::get<ServerAddress>(data);
cout << "Target: " << address.host << ":" << address.port << endl;
} else {
cout << "Message: " << std::get<std::string>(data) << endl;
}
});
}
this_thread::sleep_for(chrono::seconds{8});
resolver.finalize();
return 0;
}