From e2488227d49d84d674cc56fe767d582a4afc50f3 Mon Sep 17 00:00:00 2001 From: Maxim Sharabayko Date: Thu, 1 Dec 2022 12:48:43 +0100 Subject: [PATCH] Disable TCP stats (not fully implemented) --- xtransmit/tcp_socket.cpp | 6 +++--- xtransmit/tcp_socket.hpp | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/xtransmit/tcp_socket.cpp b/xtransmit/tcp_socket.cpp index 8f38373..d6d9f45 100644 --- a/xtransmit/tcp_socket.cpp +++ b/xtransmit/tcp_socket.cpp @@ -357,9 +357,9 @@ int socket::tcp::write(const const_buffer& buffer, int timeout_ms) return static_cast(res); } -#ifndef _WIN32 +#ifdef ENABLE_TCP_STATS namespace detail { -const string tcp_info_to_csv(int socketid, const tcp_info& stats, bool print_header) +string tcp_info_to_csv(int socketid, const tcp_info& stats, bool print_header) { std::ostringstream output; @@ -407,7 +407,7 @@ const string tcp_info_to_csv(int socketid, const tcp_info& stats, bool print_hea const string socket::tcp::statistics_csv(bool print_header) const { -#ifndef _WIN32 +#ifdef ENABLE_TCP_STATS tcp_info tcp_stats = {}; socklen_t len = sizeof tcp_stats; diff --git a/xtransmit/tcp_socket.hpp b/xtransmit/tcp_socket.hpp index 2f5316d..23ee97d 100644 --- a/xtransmit/tcp_socket.hpp +++ b/xtransmit/tcp_socket.hpp @@ -23,7 +23,7 @@ class tcp using string = std::string; public: - explicit tcp(const UriParser &src_uri); + explicit tcp(const UriParser& src_uri); tcp(const int sock, bool blocking); ~tcp(); @@ -44,12 +44,20 @@ class tcp * * @throws socket_exception Thrown on failure. */ - size_t read(const mutable_buffer &buffer, int timeout_ms = -1) final; - int write(const const_buffer &buffer, int timeout_ms = -1) final; + size_t read(const mutable_buffer& buffer, int timeout_ms = -1) final; + int write(const const_buffer& buffer, int timeout_ms = -1) final; public: - bool supports_statistics() const final { return true; } - const std::string statistics_csv(bool print_header) const final; + bool supports_statistics() const final + { +#ifdef ENABLE_TCP_STATS + return true; +#else + return false; +#endif + } + + const std::string statistics_csv(bool print_header) const final; private: void raise_exception(const string&& place, const string&& reason) const; @@ -62,8 +70,8 @@ class tcp void set_blocking_flags(bool is_blocking) const; private: - SOCKET m_bind_socket = -1; // INVALID_SOCK; - sockaddr_in m_dst_addr = {}; + SOCKET m_bind_socket = -1; // INVALID_SOCK; + sockaddr_in m_dst_addr = {}; bool m_blocking_mode = false; string m_host;