From afa058c4eef750d06742e1c7e94bfdbda873b28e Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 14 Apr 2019 18:12:11 +0100 Subject: [PATCH] Fix build on windows --- include/llarp.hpp | 3 ++- llarp/metrics/metrictank_publisher.cpp | 13 ++++++++----- llarp/metrics/publishers.cpp | 2 +- llarp/metrics/publishers.hpp | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/include/llarp.hpp b/include/llarp.hpp index d0f5457ec..fefc9632d 100644 --- a/include/llarp.hpp +++ b/include/llarp.hpp @@ -1,6 +1,7 @@ #ifndef LLARP_HPP #define LLARP_HPP +#include #include #include @@ -49,7 +50,7 @@ namespace llarp bool singleThreaded = false; bool disableMetrics = false; bool disableMetricLogs = false; - std::string jsonMetricsPath; + fs::path jsonMetricsPath; std::string metricTankHost; std::map< std::string, std::string > metricTags; diff --git a/llarp/metrics/metrictank_publisher.cpp b/llarp/metrics/metrictank_publisher.cpp index 8762ba498..d1c3bc5fe 100644 --- a/llarp/metrics/metrictank_publisher.cpp +++ b/llarp/metrics/metrictank_publisher.cpp @@ -12,7 +12,9 @@ #include #include #else +#ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN +#endif #include #include #include @@ -85,6 +87,7 @@ namespace llarp } break; } + assert(false && "Invalid publication type"); } std::string @@ -198,21 +201,21 @@ namespace llarp publishData(const std::vector< std::string > &toSend, const std::string &host, short port) { - struct addrinfo *result = NULL, hints; - bzero(&hints, sizeof(hints)); + struct addrinfo *addrs = NULL, hints; + ZeroMemory(&hints, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; const std::string portAsStr = std::to_string(port); - if(getaddrinfo(host.c_str(), portAsStr.c_str(), &hints, &result) != 0) + if(getaddrinfo(host.c_str(), portAsStr.c_str(), &hints, &addrs) != 0) { LogError("Failed to get address info"); return; } - int sock = + SOCKET sock = ::socket(addrs->ai_family, addrs->ai_socktype, addrs->ai_protocol); if(sock == INVALID_SOCKET) @@ -248,7 +251,7 @@ namespace llarp && (static_cast< size_t >(sentLen) < val.size())); } - shutdown(sock, SHUT_RDWR); + shutdown(sock, SD_SEND); closesocket(sock); } #endif diff --git a/llarp/metrics/publishers.cpp b/llarp/metrics/publishers.cpp index 33118369d..16a1b7f54 100644 --- a/llarp/metrics/publishers.cpp +++ b/llarp/metrics/publishers.cpp @@ -280,7 +280,7 @@ namespace llarp void JsonPublisher::directoryPublisher(const nlohmann::json &result, - fs::path path) + const fs::path& path) { std::ofstream fstream(path.string(), std::ios_base::app); if(!fstream) diff --git a/llarp/metrics/publishers.hpp b/llarp/metrics/publishers.hpp index 7ef2d32a9..fe0b6db2c 100644 --- a/llarp/metrics/publishers.hpp +++ b/llarp/metrics/publishers.hpp @@ -50,7 +50,7 @@ namespace llarp publish(const Sample& values) override; static void - directoryPublisher(const nlohmann::json& result, fs::path path); + directoryPublisher(const nlohmann::json& result, const fs::path& path); }; } // namespace metrics