Skip to content

Commit 6e69b59

Browse files
committed
Catch exception when resolve domain failed
1 parent 6f52615 commit 6e69b59

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/transport/TcpTransport.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,13 @@ TcpConnectStatus TcpTransport::connect(const string& strServerURL, int timeoutMi
157157
struct sockaddr_in sin;
158158
memset(&sin, 0, sizeof(sin));
159159
sin.sin_family = AF_INET;
160-
sin.sin_addr.s_addr = getInetAddr(hostname);
160+
try {
161+
sin.sin_addr.s_addr = getInetAddr(hostname);
162+
} catch (const MQClientException& e) {
163+
LOG_INFO("connect to %s failed, %s", strServerURL, e.what());
164+
setTcpConnectStatus(TCP_CONNECT_STATUS_FAILED);
165+
return TCP_CONNECT_STATUS_FAILED;
166+
}
161167
sin.sin_port = htons(port);
162168

163169
m_event.reset(EventLoop::GetDefaultEventLoop()->createBufferEvent(-1, BEV_OPT_CLOSE_ON_FREE | BEV_OPT_THREADSAFE,

0 commit comments

Comments
 (0)