I wish libpq add get_unresolv_host() and set_unresolv_host_ip() function

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&nbsp;
if ("host=" in conn_params) and ("hostaddr=" not in conn_params):
&nbsp; &nbsp;get_domain_name_and_resolv_and_add_hostaddr_to_conn_params_string()

Another way is to add it&nbsp; to libq;
I write a simple example:
&nbsp; &nbsp;&nbsp;https://github.com/gamefunc/Aiolibpq_simple
I added the code to libq the build for use:
&nbsp; &nbsp; https://github.com/gamefunc/Aiolibpq_simple/blob/main/Modify_Libpq_Source_Code.py
and use it in(awaitable<int&gt; Aiolibpq::connect()):
&nbsp; &nbsp; https://github.com/gamefunc/Aiolibpq_simple/blob/main/Aiolibpq_simple.cpp

&nbsp; &nbsp; const char* host_name = nullptr;
&nbsp; &nbsp; while((host_name = PQgetUnresolvHost(conn)) != nullptr){
&nbsp; &nbsp; &nbsp; &nbsp; tcp::resolver resolver(loop);
&nbsp; &nbsp; &nbsp; &nbsp; tcp::resolver::iterator ep_iter =&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; co_await resolver.async_resolve(
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; host_name, "", use_awaitable);
&nbsp; &nbsp; &nbsp; &nbsp; tcp::endpoint ep = *ep_iter;
&nbsp; &nbsp; &nbsp; &nbsp; PQSetUnresolvHost(
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conn, host_name,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ep.address().to_string().data(),
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ep.address().to_string().size());
&nbsp; &nbsp; }// while()

Of course, there will be many situations in this code,&nbsp;
for example, when one of the domain names fails to resolve the ip, it will boom;

Browse pgsql-hackers by date

  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