diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2014-09-04 17:45:00 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2014-09-09 15:18:18 -0400 |
commit | 69f202039823933c34ad444dd9d0cac5a66095b0 (patch) | |
tree | 544a75544a6d972abf4a709e9935c292d7bd01fd /src/mongo/db/repl/isself.cpp | |
parent | 618d0abe400d0e377691e2df5f1da77c7abf642a (diff) | |
download | mongo-69f202039823933c34ad444dd9d0cac5a66095b0.tar.gz |
SERVER-15151: use isSelf on Windows, Solaris, & FreeBSD
Diffstat (limited to 'src/mongo/db/repl/isself.cpp')
-rw-r--r-- | src/mongo/db/repl/isself.cpp | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/src/mongo/db/repl/isself.cpp b/src/mongo/db/repl/isself.cpp index 5d4f003f237..f2750051c7c 100644 --- a/src/mongo/db/repl/isself.cpp +++ b/src/mongo/db/repl/isself.cpp @@ -47,9 +47,23 @@ #include "mongo/util/scopeguard.h" #include "mongo/util/log.h" -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) || defined(__freebsd__) || defined(__sunos__) +#define FASTPATH_UNIX 1 +#endif + +#if !defined(_WIN32) && !defined(FASTPATH_UNIX) +#error isself needs to be implemented for this platform +#endif + + +#ifdef FASTPATH_UNIX #include <ifaddrs.h> #include <netdb.h> + +#ifdef __freebsd__ +#include <netinet/in.h> +#endif + #elif defined(_WIN32) #include <boost/asio/detail/socket_ops.hpp> #include <boost/scoped_array.hpp> @@ -59,10 +73,6 @@ #include <Ws2tcpip.h> #endif // defined(_WIN32) -#if defined(_WIN32) || defined(__linux__) || defined(__APPLE__) -#define FASTPATH 1 -#endif - namespace mongo { namespace repl { @@ -73,8 +83,6 @@ namespace repl { return Status::OK(); } -#ifdef FASTPATH - namespace { /** @@ -83,7 +91,7 @@ namespace { * we need gai_strerror. */ std::string stringifyError(int code) { -#if defined(__linux__) || defined(__APPLE__) +#if FASTPATH_UNIX return gai_strerror(code); #elif defined(_WIN32) // FormatMessage in errnoWithDescription works here on windows @@ -147,13 +155,8 @@ namespace { } // namespace -#endif // ifdef FASTPATH - - bool isSelf(const HostAndPort& hostAndPort) { -#ifdef FASTPATH - // Fastpath: check if the host&port in question is bound to one // of the interfaces on this machine. // No need for ip match if the ports do not match @@ -181,8 +184,6 @@ namespace { } } -#endif // ifdef FASTPATH - if (!Listener::getTimeTracker()) { // this ensures we are actually running a server // this may return true later, so may want to retry @@ -220,9 +221,8 @@ namespace { * addresses will be returned. */ std::vector<std::string> getBoundAddrs(const bool ipv6enabled) { -#ifdef FASTPATH std::vector<std::string> out; -#if defined(__linux__) || defined(__APPLE__) +#ifdef FASTPATH_UNIX ifaddrs* addrs; @@ -338,6 +338,7 @@ namespace { } #endif // defined(_WIN32) + if (logger::globalLogDomain()->shouldLog(logger::LogSeverity::Debug(2))) { StringBuilder builder; builder << "getBoundAddrs():"; @@ -347,12 +348,7 @@ namespace { LOG(2) << builder.str(); } return out; -#else // ifdef FASTPATH - invariant(false); -#endif } -#undef FASTPATH - } // namespace repl } // namespace mongo |