You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// The protocol depends on the host, both V4 and V6 are supported.
resolver_.async_resolve(request_->host(), port,
std::bind(&ClientBase::OnResolve, this, _1, _2));
}
我看了您的部分代码(主要是关于http client部分的),发现其本身就是支持异步调用的。
void ClientBase::AsyncResolve(string_view default_port) {
std::string port = request_->port();
if (port.empty()) {
port = ToString(default_port);
}
LOG_VERB("Resolve host (%s)", request_->host().c_str());
// The protocol depends on the
host
, both V4 and V6 are supported.resolver_.async_resolve(request_->host(), port,
std::bind(&ClientBase::OnResolve, this, _1, _2));
}
void ClientBase::OnResolve(boost::system::error_code ec,
tcp::resolver::results_type endpoints) {
if (ec) {
LOG_ERRO("Host resolve error (%s)", ec.message().c_str());
error_.Set(Error::kResolveError, "Host resolve error");
FinishRequest();
return;
}
LOG_VERB("Connect socket");
AsyncWaitDeadlineTimer(connect_timeout_);
socket_->AsyncConnect(request_->host(), endpoints,
std::bind(&ClientBase::OnConnect, this, _1, _2));
}
以上代码就是异步调用的。只是在ClientBase::FinishRequest函数中强行做了一个同步。
我比较好奇的是,为啥不开放异步调用接口。对整个框架其实也没有额外的负担。
The text was updated successfully, but these errors were encountered: