You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kvrocks.apache.org by GitBox <gi...@apache.org> on 2022/05/08 11:03:52 UTC
[GitHub] [incubator-kvrocks] git-hulk opened a new pull request, #554: Support to listen on ipv6 address
git-hulk opened a new pull request, #554:
URL: https://github.com/apache/incubator-kvrocks/pull/554
I didn't add test cases for this PR since the ipv6 was supported in TCL8.6, and the default TCL version on MacOSX was 8.5. So would force developers to upgrade TCL version manually if we want to add the ipv6 test cases, I think it's not worth to do that. I have tested the client and replication on my side.
Closes #491
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] git-hulk commented on a diff in pull request #554: Support to listen on ipv6 address
Posted by GitBox <gi...@apache.org>.
git-hulk commented on code in PR #554:
URL: https://github.com/apache/incubator-kvrocks/pull/554#discussion_r870018593
##########
src/worker.cc:
##########
@@ -153,27 +158,42 @@ void Worker::newUnixSocketConnection(evconnlistener *listener, evutil_socket_t f
}
}
-Status Worker::listenTCP(const std::string &host, int port, int backlog) {
- sockaddr_in sin{};
- sin.sin_family = AF_INET;
- evutil_inet_pton(AF_INET, host.data(), &(sin.sin_addr));
- sin.sin_port = htons(port);
- int fd = socket(AF_INET, SOCK_STREAM, 0);
- int sock_opt = 1;
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &sock_opt, sizeof(sock_opt)) < 0) {
- return Status(Status::NotOK, evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
- }
- // to support multi-thread binding on macOS
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &sock_opt, sizeof(sock_opt)) < 0) {
- return Status(Status::NotOK, evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
+Status Worker::listenTCP(const std::string &host, int port, int af, int backlog) {
Review Comment:
you mean move the host check inside listenTCP? If yes, I'm ok to do that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] ShooterIT commented on a diff in pull request #554: Support to listen on ipv6 address
Posted by GitBox <gi...@apache.org>.
ShooterIT commented on code in PR #554:
URL: https://github.com/apache/incubator-kvrocks/pull/554#discussion_r870891839
##########
src/worker.cc:
##########
@@ -154,26 +155,47 @@ void Worker::newUnixSocketConnection(evconnlistener *listener, evutil_socket_t f
}
Status Worker::listenTCP(const std::string &host, int port, int backlog) {
- sockaddr_in sin{};
- sin.sin_family = AF_INET;
- evutil_inet_pton(AF_INET, host.data(), &(sin.sin_addr));
- sin.sin_port = htons(port);
- int fd = socket(AF_INET, SOCK_STREAM, 0);
- int sock_opt = 1;
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &sock_opt, sizeof(sock_opt)) < 0) {
- return Status(Status::NotOK, evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
- }
- // to support multi-thread binding on macOS
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &sock_opt, sizeof(sock_opt)) < 0) {
- return Status(Status::NotOK, evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
+ char _port[6];
+ int af;
+ int rv, fd, sock_opt = 1;
Review Comment:
```suggestion
int rv, fd, af, sock_opt = 1;
```
##########
src/worker.cc:
##########
@@ -154,26 +155,47 @@ void Worker::newUnixSocketConnection(evconnlistener *listener, evutil_socket_t f
}
Status Worker::listenTCP(const std::string &host, int port, int backlog) {
- sockaddr_in sin{};
- sin.sin_family = AF_INET;
- evutil_inet_pton(AF_INET, host.data(), &(sin.sin_addr));
- sin.sin_port = htons(port);
- int fd = socket(AF_INET, SOCK_STREAM, 0);
- int sock_opt = 1;
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &sock_opt, sizeof(sock_opt)) < 0) {
- return Status(Status::NotOK, evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
- }
- // to support multi-thread binding on macOS
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &sock_opt, sizeof(sock_opt)) < 0) {
- return Status(Status::NotOK, evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
+ char _port[6];
+ int af;
+ int rv, fd, sock_opt = 1;
+
+ if (strchr(host.data(), ':')) {
+ af = AF_INET6;
+ } else {
+ af = AF_INET;
+ }
+ snprintf(_port, sizeof(_port), "%d", port);
+ struct addrinfo hints, *srv_info, *p;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = af;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_PASSIVE;
+
+ if ((rv = getaddrinfo(host.data(), _port, &hints, &srv_info)) != 0) {
Review Comment:
forget to call `freeaddrinfo` to free `addrinfo`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] git-hulk merged pull request #554: Support to listen on ipv6 address
Posted by GitBox <gi...@apache.org>.
git-hulk merged PR #554:
URL: https://github.com/apache/incubator-kvrocks/pull/554
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] ShooterIT commented on a diff in pull request #554: Support to listen on ipv6 address
Posted by GitBox <gi...@apache.org>.
ShooterIT commented on code in PR #554:
URL: https://github.com/apache/incubator-kvrocks/pull/554#discussion_r870102334
##########
src/worker.cc:
##########
@@ -153,27 +158,42 @@ void Worker::newUnixSocketConnection(evconnlistener *listener, evutil_socket_t f
}
}
-Status Worker::listenTCP(const std::string &host, int port, int backlog) {
- sockaddr_in sin{};
- sin.sin_family = AF_INET;
- evutil_inet_pton(AF_INET, host.data(), &(sin.sin_addr));
- sin.sin_port = htons(port);
- int fd = socket(AF_INET, SOCK_STREAM, 0);
- int sock_opt = 1;
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &sock_opt, sizeof(sock_opt)) < 0) {
- return Status(Status::NotOK, evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
- }
- // to support multi-thread binding on macOS
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &sock_opt, sizeof(sock_opt)) < 0) {
- return Status(Status::NotOK, evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
+Status Worker::listenTCP(const std::string &host, int port, int af, int backlog) {
Review Comment:
yes, i think it will be more generic.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] git-hulk commented on a diff in pull request #554: Support to listen on ipv6 address
Posted by GitBox <gi...@apache.org>.
git-hulk commented on code in PR #554:
URL: https://github.com/apache/incubator-kvrocks/pull/554#discussion_r870302797
##########
src/worker.cc:
##########
@@ -153,27 +158,42 @@ void Worker::newUnixSocketConnection(evconnlistener *listener, evutil_socket_t f
}
}
-Status Worker::listenTCP(const std::string &host, int port, int backlog) {
- sockaddr_in sin{};
- sin.sin_family = AF_INET;
- evutil_inet_pton(AF_INET, host.data(), &(sin.sin_addr));
- sin.sin_port = htons(port);
- int fd = socket(AF_INET, SOCK_STREAM, 0);
- int sock_opt = 1;
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &sock_opt, sizeof(sock_opt)) < 0) {
- return Status(Status::NotOK, evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
- }
- // to support multi-thread binding on macOS
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &sock_opt, sizeof(sock_opt)) < 0) {
- return Status(Status::NotOK, evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
+Status Worker::listenTCP(const std::string &host, int port, int af, int backlog) {
Review Comment:
OK, nice advice.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] ShooterIT commented on a diff in pull request #554: Support to listen on ipv6 address
Posted by GitBox <gi...@apache.org>.
ShooterIT commented on code in PR #554:
URL: https://github.com/apache/incubator-kvrocks/pull/554#discussion_r869989855
##########
src/worker.cc:
##########
@@ -153,27 +158,42 @@ void Worker::newUnixSocketConnection(evconnlistener *listener, evutil_socket_t f
}
}
-Status Worker::listenTCP(const std::string &host, int port, int backlog) {
- sockaddr_in sin{};
- sin.sin_family = AF_INET;
- evutil_inet_pton(AF_INET, host.data(), &(sin.sin_addr));
- sin.sin_port = htons(port);
- int fd = socket(AF_INET, SOCK_STREAM, 0);
- int sock_opt = 1;
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &sock_opt, sizeof(sock_opt)) < 0) {
- return Status(Status::NotOK, evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
- }
- // to support multi-thread binding on macOS
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &sock_opt, sizeof(sock_opt)) < 0) {
- return Status(Status::NotOK, evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
+Status Worker::listenTCP(const std::string &host, int port, int af, int backlog) {
Review Comment:
i don't think `af` should be a argument. you can judge host inner to check ipv4 or ipv6. so when calling, we don't need two statements
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] git-hulk commented on a diff in pull request #554: Support to listen on ipv6 address
Posted by GitBox <gi...@apache.org>.
git-hulk commented on code in PR #554:
URL: https://github.com/apache/incubator-kvrocks/pull/554#discussion_r871055364
##########
src/worker.cc:
##########
@@ -154,26 +155,47 @@ void Worker::newUnixSocketConnection(evconnlistener *listener, evutil_socket_t f
}
Status Worker::listenTCP(const std::string &host, int port, int backlog) {
- sockaddr_in sin{};
- sin.sin_family = AF_INET;
- evutil_inet_pton(AF_INET, host.data(), &(sin.sin_addr));
- sin.sin_port = htons(port);
- int fd = socket(AF_INET, SOCK_STREAM, 0);
- int sock_opt = 1;
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &sock_opt, sizeof(sock_opt)) < 0) {
- return Status(Status::NotOK, evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
- }
- // to support multi-thread binding on macOS
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &sock_opt, sizeof(sock_opt)) < 0) {
- return Status(Status::NotOK, evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
+ char _port[6];
+ int af;
+ int rv, fd, sock_opt = 1;
+
+ if (strchr(host.data(), ':')) {
+ af = AF_INET6;
+ } else {
+ af = AF_INET;
+ }
+ snprintf(_port, sizeof(_port), "%d", port);
+ struct addrinfo hints, *srv_info, *p;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = af;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_PASSIVE;
+
+ if ((rv = getaddrinfo(host.data(), _port, &hints, &srv_info)) != 0) {
Review Comment:
good catch, will fix later.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org