-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ISSUE #42] Fixed this issue that cann't set namesrv with hostname #98
Conversation
src/transport/TcpTransport.cpp
Outdated
@@ -65,6 +65,41 @@ tcpConnectStatus TcpTransport::connect(const string &strServerURL, | |||
memset(&sin, 0, sizeof(sin)); | |||
sin.sin_family = AF_INET; | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please write a new function or method, and call it.
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rebase two commits to only one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format this file with clang-format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to rebase commits since we use suqash and merge
button to merge PRs.
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename s
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.