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&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;

Reply via email to