[ISSUE #42] Fixed this issue that cann't set namesrv with hostname#98
[ISSUE #42] Fixed this issue that cann't set namesrv with hostname#98ShannonDing merged 3 commits intoapache:masterfrom
Conversation
src/transport/TcpTransport.cpp
Outdated
| sin.sin_addr.s_addr = inet_addr(hostName.c_str()); | ||
|
|
||
| if (sin.sin_addr.s_addr == INADDR_NONE) { | ||
| struct evutil_addrinfo hints; |
There was a problem hiding this comment.
please write a new function or method, and call it.
| } | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
rebase two commits to only one.
There was a problem hiding this comment.
format this file with clang-format.
There was a problem hiding this comment.
There is no need to rebase commits since we use suqash and merge button to merge PRs.
| } | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
There is no need to rebase commits since we use suqash and merge button to merge PRs.
src/transport/TcpTransport.cpp
Outdated
| /* Look up the hostname. */ | ||
| int err = evutil_getaddrinfo(hostName.c_str(), NULL, &hints, &answer); | ||
| if (err != 0) { | ||
| string info = "Error while resolving " + hostName + ":" + evutil_gai_strerror(err); |
There was a problem hiding this comment.
std::string errorMessage = "Failed to resolve host name(" + hostName + "): " + evutil_gai_strerror(err);
src/transport/TcpTransport.cpp
Outdated
| /* Build the hints to tell getaddrinfo how to act. */ | ||
| memset(&hints, 0, sizeof(hints)); | ||
| hints.ai_family = AF_UNSPEC; /* v4 or v6 is fine. */ | ||
| /* Look up the hostname. */ |
There was a problem hiding this comment.
// Look up the hostname.
src/transport/TcpTransport.cpp
Outdated
| struct evutil_addrinfo *answer = NULL; | ||
| /* Build the hints to tell getaddrinfo how to act. */ | ||
| memset(&hints, 0, sizeof(hints)); | ||
| hints.ai_family = AF_UNSPEC; /* v4 or v6 is fine. */ |
There was a problem hiding this comment.
write the comment at the line before this line.
src/transport/TcpTransport.cpp
Outdated
| } | ||
|
|
||
| struct evutil_addrinfo *ai; | ||
| for (ai = answer; ai; ai = ai->ai_next){ |
There was a problem hiding this comment.
1.rename ai to a more meaningful name.
2.
for (ai = answer; ai != nullptr; ai = ai->ai_next) {
src/transport/TcpTransport.cpp
Outdated
| char buf[128]; | ||
| const char *s = NULL; | ||
| if (ai->ai_family == AF_INET) { | ||
| struct sockaddr_in *sin = (struct sockaddr_in*)ai->ai_addr; |
There was a problem hiding this comment.
ues reinterpret_cast here
src/transport/TcpTransport.cpp
Outdated
|
|
||
| struct evutil_addrinfo *ai; | ||
| for (ai = answer; ai; ai = ai->ai_next){ | ||
| char buf[128]; |
There was a problem hiding this comment.
constexpr size_t length = 128;we should avoid magic number.
src/transport/TcpTransport.cpp
Outdated
| const char *s = NULL; | ||
| if (ai->ai_family == AF_INET) { | ||
| struct sockaddr_in *sin = (struct sockaddr_in*)ai->ai_addr; | ||
| s = evutil_inet_ntop(AF_INET, &sin->sin_addr, buf, 128); |
What is the purpose of the change
Fixed this issue that cann't set namesrv with hostname
Brief changelog
Modify TcpTransport::connect
Calling inet_addr for a domain name returns INADDR_NONE
If return INADDR_NONE call gethostbyname get IP ADDRESS
Verifying this change
roducer->setNamesrvAddr("mq.***.com:9876");
Follow this checklist to help us incorporate your contribution quickly and easily. Notice,
it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR.[ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.