mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
Forward declare ares_channel and apply -wno-reserved-identifier to CARESPTRResolver unit
This commit is contained in:
parent
4f4acfabe5
commit
5c221464ba
@ -439,7 +439,7 @@ if (TARGET ch_contrib::avrocpp)
|
||||
dbms_target_link_libraries(PRIVATE ch_contrib::avrocpp)
|
||||
endif ()
|
||||
|
||||
target_compile_options(clickhouse_common_io PRIVATE -Wno-reserved-identifier)
|
||||
set_source_files_properties(Common/CARESPTRResolver.cpp PROPERTIES COMPILE_FLAGS -Wno-reserved-identifier)
|
||||
target_link_libraries (clickhouse_common_io PRIVATE ch_contrib::c-ares)
|
||||
|
||||
if (TARGET OpenSSL::Crypto)
|
||||
|
@ -1,20 +1,21 @@
|
||||
#include <arpa/inet.h>
|
||||
#include "CARESPTRResolver.h"
|
||||
#include "netdb.h"
|
||||
#include "ares.h"
|
||||
|
||||
namespace DB {
|
||||
static void callback(void * arg, int status, int, struct hostent * host) {
|
||||
auto * ptr_records = reinterpret_cast<std::vector<std::string>*>(arg);
|
||||
if (status == ARES_SUCCESS) {
|
||||
int i = 0;
|
||||
while (auto ptr_record = host->h_aliases[i]) {
|
||||
while (auto * ptr_record = host->h_aliases[i]) {
|
||||
ptr_records->emplace_back(ptr_record);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CARESPTRResolver::CARESPTRResolver() {
|
||||
CARESPTRResolver::CARESPTRResolver() : channel(std::make_shared<ares_channel>()) {
|
||||
init();
|
||||
}
|
||||
|
||||
@ -32,13 +33,13 @@ namespace DB {
|
||||
}
|
||||
|
||||
void CARESPTRResolver::init() {
|
||||
if (ares_init(&channel) != ARES_SUCCESS){
|
||||
if (ares_init(channel.get()) != ARES_SUCCESS){
|
||||
throw std::exception {};
|
||||
}
|
||||
}
|
||||
|
||||
void CARESPTRResolver::deinit() {
|
||||
ares_destroy(channel);
|
||||
ares_destroy(*channel);
|
||||
ares_library_cleanup();
|
||||
}
|
||||
|
||||
@ -46,7 +47,7 @@ namespace DB {
|
||||
in_addr addr;
|
||||
inet_aton(ip.c_str(), &addr);
|
||||
|
||||
ares_gethostbyaddr(channel, reinterpret_cast<const char*>(&addr), sizeof(addr), AF_INET, callback, &response);
|
||||
ares_gethostbyaddr(*channel, reinterpret_cast<const char*>(&addr), sizeof(addr), AF_INET, callback, &response);
|
||||
}
|
||||
|
||||
void CARESPTRResolver::wait() {
|
||||
@ -57,13 +58,13 @@ namespace DB {
|
||||
|
||||
FD_ZERO(&read_fds);
|
||||
FD_ZERO(&write_fds);
|
||||
nfds = ares_fds(channel, &read_fds, &write_fds);
|
||||
if(nfds == 0){
|
||||
nfds = ares_fds(*channel, &read_fds, &write_fds);
|
||||
if(nfds == 0) {
|
||||
break;
|
||||
}
|
||||
tvp = ares_timeout(channel, nullptr, &tv);
|
||||
tvp = ares_timeout(*channel, nullptr, &tv);
|
||||
select(nfds, &read_fds, &write_fds, nullptr, tvp);
|
||||
ares_process(channel, &read_fds, &write_fds);
|
||||
ares_process(*channel, &read_fds, &write_fds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "DNSPTRResolver.h"
|
||||
#include "ares.h"
|
||||
|
||||
using ares_channel = struct ares_channeldata *;
|
||||
|
||||
namespace DB {
|
||||
class CARESPTRResolver : public DNSPTRResolver {
|
||||
|
||||
public:
|
||||
CARESPTRResolver();
|
||||
~CARESPTRResolver() override;
|
||||
@ -13,14 +13,13 @@ namespace DB {
|
||||
std::vector<std::string> resolve(const std::string & ip) override;
|
||||
|
||||
private:
|
||||
|
||||
void init();
|
||||
void deinit();
|
||||
void wait();
|
||||
|
||||
void resolve(const std::string & ip, std::vector<std::string> & response);
|
||||
|
||||
ares_channel channel;
|
||||
std::shared_ptr<ares_channel> channel;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user