BewareMyPower commented on code in PR #539:
URL: https://github.com/apache/pulsar-client-cpp/pull/539#discussion_r2871285347
##########
lib/ClientConnection.cc:
##########
@@ -486,7 +486,7 @@ void ClientConnection::handleTcpConnected(const ASIO_ERROR&
err, const tcp::endp
handleHandshake(ASIO_SUCCESS);
}
} else {
- LOG_ERROR(cnxString_ << "Failed to establish connection: " <<
err.message());
+ LOG_ERROR(cnxString_ << "Failed to establish connection to " <<
endpoint.address().to_string() << ":" << endpoint.port() << ": " <<
err.message());
Review Comment:
`endpoint` can be accepted by `ostream::operator<<` directly:
```c++
LOG_ERROR("xxx" << endpoint);
```
https://think-async.com/Asio/asio-1.36.0/doc/asio/reference/ip__basic_endpoint/operator_lt__lt_.html
The implementation already includes the address and port (source code: asio
1.32):
```c++
template <typename Elem, typename Traits, typename InternetProtocol>
std::basic_ostream<Elem, Traits>& operator<<(
std::basic_ostream<Elem, Traits>& os,
const basic_endpoint<InternetProtocol>& endpoint)
{
asio::ip::detail::endpoint tmp_ep(endpoint.address(), endpoint.port());
return os << tmp_ep.to_string().c_str();
}
```
##########
lib/ClientConnection.cc:
##########
@@ -603,15 +603,29 @@ void ClientConnection::handleResolve(ASIO_ERROR err,
const tcp::resolver::result
return;
}
+ tcp::endpoint endpointToLog;
+ if (!results.empty()) {
+ endpointToLog = *results.begin();
+ LOG_DEBUG(cnxString_ << "Resolved " << results.size() << " endpoints");
+ for (const auto& endpoint : results) {
+ LOG_DEBUG(cnxString_ << " " <<
endpoint.endpoint().address().to_string() << ":" << endpoint.endpoint().port());
+ }
+ }
+
auto weakSelf = weak_from_this();
- connectTimeoutTask_->setCallback([weakSelf](const PeriodicTask::ErrorCode&
ec) {
+ connectTimeoutTask_->setCallback([weakSelf, endpointToLog](const
PeriodicTask::ErrorCode& ec) {
Review Comment:
Instead of capturing the 1st endpoint in the DNS results, it would be better
to pass all endpoints and log them for failures.
```c++
static std::ostream& operator<<(std::ostream& os, const
tcp::resolver::results_type& results) {
for (const auto& entry : results) {
os << entry.endpoint() << " ";
}
return os;
}
```
```c++
connectTimeoutTask_->setCallback([weakSelf, results](const
PeriodicTask::ErrorCode& ec) {
/* ... */
if (ptr->state_ != Ready) {
LOG_ERROR(ptr->cnxString_ << "Connection to " << results << "was
not established in "
<<
ptr->connectTimeoutTask_->getPeriodMs() << " ms, close the socket");
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]