@@ -56,6 +56,16 @@ using namespace ASIO::ip;
5656
5757namespace pulsar {
5858
59+ namespace {
60+ static std::ostream& operator <<(std::ostream& os, const tcp::resolver::results_type& results) {
61+ for (const auto & entry : results) {
62+ const auto & ep = entry.endpoint ();
63+ os << ep.address ().to_string () << " :" << ep.port () << " " ;
64+ }
65+ return os;
66+ }
67+ } // anonymous namespace
68+
5969using proto::BaseCommand;
6070
6171static const uint32_t DefaultBufferSize = 64 * 1024 ;
@@ -486,7 +496,7 @@ void ClientConnection::handleTcpConnected(const ASIO_ERROR& err, const tcp::endp
486496 handleHandshake (ASIO_SUCCESS);
487497 }
488498 } else {
489- LOG_ERROR (cnxString_ << " Failed to establish connection to " << endpoint. address (). to_string () << " : " << endpoint. port () << " : " << err.message ());
499+ LOG_ERROR (cnxString_ << " Failed to establish connection to " << endpoint << " : " << err.message ());
490500 if (err == ASIO::error::operation_aborted) {
491501 close ();
492502 } else {
@@ -603,30 +613,24 @@ void ClientConnection::handleResolve(ASIO_ERROR err, const tcp::resolver::result
603613 return ;
604614 }
605615
606- tcp::endpoint endpointToLog;
607616 if (!results.empty ()) {
608- endpointToLog = *results.begin ();
609617 LOG_DEBUG (cnxString_ << " Resolved " << results.size () << " endpoints" );
610- for (const auto & endpoint : results) {
611- LOG_DEBUG (cnxString_ << " " << endpoint.endpoint ().address ().to_string () << " :" << endpoint.endpoint ().port ());
618+ for (const auto & entry : results) {
619+ const auto & ep = entry.endpoint ();
620+ LOG_DEBUG (cnxString_ << " " << ep.address ().to_string () << " :" << ep.port ());
612621 }
613622 }
614623
615624 auto weakSelf = weak_from_this ();
616- connectTimeoutTask_->setCallback ([weakSelf, endpointToLog ](const PeriodicTask::ErrorCode& ec) {
625+ connectTimeoutTask_->setCallback ([weakSelf, results = tcp::resolver::results_type (results) ](const PeriodicTask::ErrorCode& ec) {
617626 ClientConnectionPtr ptr = weakSelf.lock ();
618627 if (!ptr) {
619- // Connection was already destroyed
628+ LOG_DEBUG ( " Connect timeout callback skipped: connection was already destroyed" );
620629 return ;
621630 }
622631
623632 if (ptr->state_ != Ready) {
624- if (endpointToLog.port () != 0 ) {
625- LOG_ERROR (ptr->cnxString_ << " Connection timeout to " << endpointToLog.address ().to_string () << " :" << endpointToLog.port ());
626- } else {
627- LOG_ERROR (ptr->cnxString_ << " Connection timeout to physical address " << ptr->physicalAddress_ );
628- }
629- LOG_ERROR (ptr->cnxString_ << " Connection was not established in "
633+ LOG_ERROR (ptr->cnxString_ << " Connection to " << results << " was not established in "
630634 << ptr->connectTimeoutTask_ ->getPeriodMs () << " ms, close the socket" );
631635 PeriodicTask::ErrorCode err;
632636 ptr->socket_ ->close (err);
0 commit comments