зеркало из https://github.com/microsoft/CCF.git
TCP listens resolve synchronously (#70)
* Ignore debug * DNS::resolve is optionally asynchronous * TCP::listen resolves synchronously
This commit is contained in:
Родитель
ef92e77ee5
Коммит
750026e7bd
|
@ -16,3 +16,4 @@ obj/
|
|||
tests/env/
|
||||
getting_started/create_vm/generated
|
||||
sphinx/env/
|
||||
debug/
|
||||
|
|
|
@ -15,7 +15,8 @@ namespace asynchost
|
|||
const std::string& host,
|
||||
const std::string& service,
|
||||
void* ud,
|
||||
uv_getaddrinfo_cb cb)
|
||||
uv_getaddrinfo_cb cb,
|
||||
bool async)
|
||||
{
|
||||
struct addrinfo hints;
|
||||
hints.ai_family = PF_INET;
|
||||
|
@ -28,18 +29,39 @@ namespace asynchost
|
|||
|
||||
int rc;
|
||||
|
||||
if (
|
||||
(rc = uv_getaddrinfo(
|
||||
uv_default_loop(),
|
||||
resolver,
|
||||
cb,
|
||||
host.c_str(),
|
||||
service.c_str(),
|
||||
&hints)) < 0)
|
||||
if (async)
|
||||
{
|
||||
LOG_FAIL << "uv_getaddrinfo failed: " << uv_strerror(rc) << std::endl;
|
||||
delete resolver;
|
||||
return false;
|
||||
if (
|
||||
(rc = uv_getaddrinfo(
|
||||
uv_default_loop(),
|
||||
resolver,
|
||||
cb,
|
||||
host.c_str(),
|
||||
service.c_str(),
|
||||
&hints)) < 0)
|
||||
{
|
||||
LOG_FAIL << "uv_getaddrinfo failed: " << uv_strerror(rc) << std::endl;
|
||||
delete resolver;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (
|
||||
(rc = uv_getaddrinfo(
|
||||
uv_default_loop(),
|
||||
resolver,
|
||||
nullptr,
|
||||
host.c_str(),
|
||||
service.c_str(),
|
||||
&hints)) < 0)
|
||||
{
|
||||
LOG_FAIL << "uv_getaddrinfo failed: " << uv_strerror(rc) << std::endl;
|
||||
delete resolver;
|
||||
return false;
|
||||
}
|
||||
|
||||
cb(resolver, rc, &hints);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -138,7 +138,7 @@ namespace asynchost
|
|||
bool listen(const std::string& host, const std::string& service)
|
||||
{
|
||||
assert_status(FRESH, LISTENING_RESOLVING);
|
||||
return resolve(host, service);
|
||||
return resolve(host, service, false);
|
||||
}
|
||||
|
||||
bool write(size_t len, const uint8_t* data)
|
||||
|
@ -282,7 +282,8 @@ namespace asynchost
|
|||
status = to;
|
||||
}
|
||||
|
||||
bool resolve(const std::string& host, const std::string& service)
|
||||
bool resolve(
|
||||
const std::string& host, const std::string& service, bool async = true)
|
||||
{
|
||||
this->host = host;
|
||||
this->service = service;
|
||||
|
@ -294,7 +295,7 @@ namespace asynchost
|
|||
addr_current = nullptr;
|
||||
}
|
||||
|
||||
if (!DNS::resolve(host, service, this, on_resolved))
|
||||
if (!DNS::resolve(host, service, this, on_resolved, async))
|
||||
{
|
||||
status = RESOLVING_FAILED;
|
||||
return false;
|
||||
|
|
Загрузка…
Ссылка в новой задаче