You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2017/07/11 01:38:48 UTC
[02/50] mesos git commit: Windows: Switched from `gethostname` to
`GetComputerName`.
Windows: Switched from `gethostname` to `GetComputerName`.
The former can inordinately slow on Windows (about 5 seconds),
whereas the latter is guaranteed to return instantly.
Because `os::internal::nodename()` and `net::hostname()` now
implement the exact same feature, we just reuse the first in
the second.
Review: https://reviews.apache.org/r/60293/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/a4bfabfd
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/a4bfabfd
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/a4bfabfd
Branch: refs/heads/master
Commit: a4bfabfdc89a6d597127d3f4e17805911912c535
Parents: 0f6c212
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Tue Jun 27 13:45:37 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 15:55:09 2017 -0700
----------------------------------------------------------------------
3rdparty/stout/include/stout/net.hpp | 24 -------------------
3rdparty/stout/include/stout/posix/net.hpp | 26 +++++++++++++++++++++
3rdparty/stout/include/stout/windows/net.hpp | 10 +++++++-
3rdparty/stout/include/stout/windows/os.hpp | 28 ++++++++++++++---------
4 files changed, 52 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/a4bfabfd/3rdparty/stout/include/stout/net.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/net.hpp b/3rdparty/stout/include/stout/net.hpp
index 425544e..f9fbd51 100644
--- a/3rdparty/stout/include/stout/net.hpp
+++ b/3rdparty/stout/include/stout/net.hpp
@@ -206,30 +206,6 @@ inline struct addrinfo createAddrInfo(int socktype, int family, int flags)
}
-inline Try<std::string> hostname()
-{
- char host[512];
-
- if (gethostname(host, sizeof(host)) < 0) {
- return ErrnoError();
- }
-
- struct addrinfo hints = createAddrInfo(SOCK_STREAM, AF_UNSPEC, AI_CANONNAME);
- struct addrinfo* result = nullptr;
-
- int error = getaddrinfo(host, nullptr, &hints, &result);
-
- if (error != 0) {
- return Error(gai_strerror(error));
- }
-
- std::string hostname = result->ai_canonname;
- freeaddrinfo(result);
-
- return hostname;
-}
-
-
// Returns a Try of the hostname for the provided IP. If the hostname
// cannot be resolved, then a string version of the IP address is
// returned.
http://git-wip-us.apache.org/repos/asf/mesos/blob/a4bfabfd/3rdparty/stout/include/stout/posix/net.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/posix/net.hpp b/3rdparty/stout/include/stout/posix/net.hpp
index 59463a0..841d9ca 100644
--- a/3rdparty/stout/include/stout/posix/net.hpp
+++ b/3rdparty/stout/include/stout/posix/net.hpp
@@ -45,6 +45,32 @@ inline Try<std::set<std::string>> links()
}
+inline struct addrinfo createAddrInfo(int socktype, int family, int flags);
+
+inline Try<std::string> hostname()
+{
+ char host[512];
+
+ if (gethostname(host, sizeof(host)) < 0) {
+ return ErrnoError();
+ }
+
+ struct addrinfo hints = createAddrInfo(SOCK_STREAM, AF_UNSPEC, AI_CANONNAME);
+ struct addrinfo* result = nullptr;
+
+ int error = getaddrinfo(host, nullptr, &hints, &result);
+
+ if (error != 0) {
+ return Error(gai_strerror(error));
+ }
+
+ std::string hostname = result->ai_canonname;
+ freeaddrinfo(result);
+
+ return hostname;
+}
+
+
// Returns a `Try` of the result of attempting to set the `hostname`.
inline Try<Nothing> setHostname(const std::string& hostname)
{
http://git-wip-us.apache.org/repos/asf/mesos/blob/a4bfabfd/3rdparty/stout/include/stout/windows/net.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/net.hpp b/3rdparty/stout/include/stout/windows/net.hpp
index 987ab70..6df4916 100644
--- a/3rdparty/stout/include/stout/windows/net.hpp
+++ b/3rdparty/stout/include/stout/windows/net.hpp
@@ -23,8 +23,10 @@
#include <stout/error.hpp>
#include <stout/foreach.hpp>
#include <stout/nothing.hpp>
+#include <stout/stringify.hpp>
#include <stout/try.hpp>
#include <stout/windows.hpp>
+#include <stout/windows/os.hpp>
namespace net {
@@ -64,10 +66,16 @@ inline Try<std::set<std::string>> links()
}
+inline Try<std::string> hostname()
+{
+ return os::internal::nodename();
+}
+
+
// Returns a `Try` of the result of attempting to set the `hostname`.
inline Try<Nothing> setHostname(const std::string& hostname)
{
- if (SetComputerName(hostname.c_str()) == 0) {
+ if (::SetComputerNameW(wide_stringify(hostname).data()) == 0) {
return WindowsError();
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/a4bfabfd/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/stout/include/stout/windows/os.hpp
index f1722d5..397ea0a 100644
--- a/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/stout/include/stout/windows/os.hpp
@@ -70,23 +70,29 @@ inline Try<OSVERSIONINFOEX> os_version()
inline Try<std::string> nodename()
{
- // Get DNS name of the local computer. First, find the size of the output
- // buffer.
+ // MSDN documentation states "The names are established at system startup,
+ // when the system reads them from the registry." This is akin to the
+ // Linux `gethostname` which calls `uname`, thus avoiding a DNS lookup.
+ // The `net::getHostname` function can be used for an explicit DNS lookup.
+ //
+ // NOTE: This returns the hostname of the local computer, or the local
+ // node if this computer is part of a cluster.
+ COMPUTER_NAME_FORMAT format = ComputerNamePhysicalDnsHostname;
DWORD size = 0;
- if (!::GetComputerNameEx(ComputerNameDnsHostname, nullptr, &size) &&
- ::GetLastError() != ERROR_MORE_DATA) {
- return WindowsError(
- "os::internal::nodename: Call to `GetComputerNameEx` failed");
+ if (::GetComputerNameExW(format, nullptr, &size) == 0) {
+ if (GetLastError() != ERROR_MORE_DATA) {
+ return WindowsError();
+ }
}
- std::unique_ptr<char[]> name(new char[size + 1]);
+ std::vector<wchar_t> buffer;
+ buffer.reserve(size);
- if (!::GetComputerNameEx(ComputerNameDnsHostname, name.get(), &size)) {
- return WindowsError(
- "os::internal::nodename: Call to `GetComputerNameEx` failed");
+ if (::GetComputerNameExW(format, buffer.data(), &size) == 0) {
+ return WindowsError();
}
- return std::string(name.get());
+ return stringify(std::wstring(buffer.data()));
}