Skip to content
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

Merged
merged 3 commits into from
Mar 18, 2019

Conversation

wangjuneng
Copy link
Contributor

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.

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test(over 80% coverage) to verify your logic correction, more mock a little better when a cross-module dependency exists.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

@wangjuneng wangjuneng changed the title [ISSUE #71] Fixed this issue that cann't set namesrv with hostname [ISSUE #42] Fixed this issue that cann't set namesrv with hostname Feb 26, 2019
@@ -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;
Copy link
Contributor

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.

}
}
}

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

}
}
}

Copy link
Contributor

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.

/* 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);
Copy link
Contributor

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);

/* 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. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Look up the hostname.

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. */
Copy link
Contributor

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.

}

struct evutil_addrinfo *ai;
for (ai = answer; ai; ai = ai->ai_next){
Copy link
Contributor

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) {

char buf[128];
const char *s = NULL;
if (ai->ai_family == AF_INET) {
struct sockaddr_in *sin = (struct sockaddr_in*)ai->ai_addr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ues reinterpret_cast here


struct evutil_addrinfo *ai;
for (ai = answer; ai; ai = ai->ai_next){
char buf[128];
Copy link
Contributor

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.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename s

@ShannonDing ShannonDing added the enhancement New feature or request label Mar 14, 2019
@ShannonDing ShannonDing added this to the 1.2.2 milestone Mar 14, 2019
@ShannonDing ShannonDing merged commit da49964 into apache:master Mar 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants