From: | 32686647 <32686647(at)qq(dot)com> |
---|---|
To: | pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | I wish libpq add get_unresolv_host() and set_unresolv_host_ip() function |
Date: | 2023-02-20 12:17:07 |
Message-ID: | tencent_3A0AC5A22E9F0522BDA357FFC46FAB4FBB06@qq.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
I want to resolve the domain name asynchronously before connecting to the target;
one way is parse sql connect parameters string; like
if ("host=" in conn_params) and ("hostaddr=" not in conn_params):
get_domain_name_and_resolv_and_add_hostaddr_to_conn_params_string()
Another way is to add it to libq;
I write a simple example:
https://github.com/gamefunc/Aiolibpq_simple
I added the code to libq the build for use:
https://github.com/gamefunc/Aiolibpq_simple/blob/main/Modify_Libpq_Source_Code.py
and use it in(awaitable<int> Aiolibpq::connect()):
https://github.com/gamefunc/Aiolibpq_simple/blob/main/Aiolibpq_simple.cpp
const char* host_name = nullptr;
while((host_name = PQgetUnresolvHost(conn)) != nullptr){
tcp::resolver resolver(loop);
tcp::resolver::iterator ep_iter =
co_await resolver.async_resolve(
host_name, "", use_awaitable);
tcp::endpoint ep = *ep_iter;
PQSetUnresolvHost(
conn, host_name,
ep.address().to_string().data(),
ep.address().to_string().size());
}// while()
Of course, there will be many situations in this code,
for example, when one of the domain names fails to resolve the ip, it will boom;
From | Date | Subject | |
---|---|---|---|
Next Message | Nazir Bilal Yavuz | 2023-02-20 12:33:29 | Re: meson: Non-feature feature options |
Previous Message | Thomas Munro | 2023-02-20 12:13:57 | Re: File descriptors in exec'd subprocesses |