Fix IPv6 on FreeBSD.
On FreeBSD (and possibly other BSDs), binding to ipv6 is restricted unless the
sysctl net.inet6.ip6.v6only=0 or the socket option IPV6_V6ONLY is turned off.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@666367 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/server/TNonblockingServer.cpp b/lib/cpp/src/server/TNonblockingServer.cpp
index ebe85a6..e376f97 100644
--- a/lib/cpp/src/server/TNonblockingServer.cpp
+++ b/lib/cpp/src/server/TNonblockingServer.cpp
@@ -590,6 +590,14 @@
throw TException("TNonblockingServer::serve() socket() -1");
}
+ #ifdef IPV6_V6ONLY
+ int zero = 0;
+ if (-1 == setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &zero, sizeof(zero))) {
+ GlobalOutput("TServerSocket::listen() IPV6_V6ONLY");
+ }
+ #endif // #ifdef IPV6_V6ONLY
+
+
int one = 1;
// Set reuseaddr to avoid 2MSL delay on server restart