Advertisement
AntonyZhilin

Untitled

Jul 28th, 2023
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. Index: userver/universal/src/hostinfo/blocking/get_hostname.cpp
  2. IDEA additional info:
  3. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  4. <+>UTF-8
  5. ===================================================================
  6. diff --git a/userver/universal/src/hostinfo/blocking/get_hostname.cpp b/userver/universal/src/hostinfo/blocking/get_hostname.cpp
  7. --- a/userver/universal/src/hostinfo/blocking/get_hostname.cpp
  8. +++ b/userver/universal/src/hostinfo/blocking/get_hostname.cpp
  9. @@ -20,18 +20,21 @@
  10. const auto kHostNameMax = MAXHOSTNAMELEN;
  11. #endif /* HOST_NAME_MAX */
  12.  
  13. -} // namespace
  14. +/*constinit*/ std::array<char, kHostNameMax> host_name{};
  15.  
  16. -std::string GetRealHostName() {
  17. - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init): performance
  18. - std::array<char, kHostNameMax> host_name;
  19. +std::string_view DoGetRealHostName() {
  20. if (::gethostname(host_name.data(), host_name.size()) == -1) {
  21. const auto code = std::make_error_code(std::errc{errno});
  22. throw std::system_error(code, "Error while getting hostname");
  23. }
  24. -
  25. - return host_name.data();
  26. + return std::string_view{host_name.data()};
  27. }
  28. +
  29. +const std::string_view host_name_view = DoGetRealHostName();
  30. +
  31. +} // namespace
  32. +
  33. +std::string GetRealHostName() { return std::string{host_name_view}; }
  34.  
  35. } // namespace hostinfo::blocking
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement