From 02afc8b64055d1d361e1c9a6384a308617bf8144 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Wed, 12 Aug 2015 20:55:07 -0400 Subject: [PATCH 1/5] Added utp-stats bjam option to enable utp stream log (utp.log file). --- Jamfile | 3 +++ include/libtorrent/utp_stream.hpp | 5 +++++ src/utp_stream.cpp | 32 +++++++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Jamfile b/Jamfile index 1dbd74330..ee1a7f276 100644 --- a/Jamfile +++ b/Jamfile @@ -472,6 +472,9 @@ feature.compose full : TORRENT_EXPENSIVE_INVARIANT_CHE feature disk-stats : off on : composite propagated link-incompatible ; feature.compose on : TORRENT_DISK_STATS ; +feature utp-stats : off on : composite propagated link-incompatible ; +feature.compose on : TORRENT_UTP_LOG TORRENT_VERBOSE_UTP_LOG ; + feature simulate-slow-read : off on : composite propagated ; feature.compose on : TORRENT_SIMULATE_SLOW_READ ; diff --git a/include/libtorrent/utp_stream.hpp b/include/libtorrent/utp_stream.hpp index fd4a4cb3d..f9473af71 100644 --- a/include/libtorrent/utp_stream.hpp +++ b/include/libtorrent/utp_stream.hpp @@ -468,6 +468,11 @@ public: issue_write(); } +#ifdef TORRENT_UTP_LOG + static bool utp_stream_log(); + static void utp_stream_log(bool enable); +#endif + private: // explicitly disallow assignment, to silence msvc warning utp_stream& operator=(utp_stream const&); diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index fcc4aea4f..f5b444a39 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -44,9 +44,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#define TORRENT_UTP_LOG 0 -#define TORRENT_VERBOSE_UTP_LOG 0 - // the behavior of the sequence numbers as implemented by uTorrent is not // particularly regular. This switch indicates the odd parts. #define TORRENT_UT_SEQ 1 @@ -70,7 +67,7 @@ static struct utp_logger utp_logger() : utp_log_file(0) { - utp_log_file = fopen("utp.log", "w+"); + utp_log_file = NULL; } ~utp_logger() { @@ -80,6 +77,8 @@ static struct utp_logger void utp_log(char const* fmt, ...) { + if (log_file_holder.utp_log_file == NULL) return; + mutex::scoped_lock lock(log_file_holder.utp_log_mutex); static time_point start = clock_type::now(); fprintf(log_file_holder.utp_log_file, "[%012" PRId64 "] ", total_microseconds(clock_type::now() - start)); @@ -1172,6 +1171,31 @@ void utp_stream::do_connect(tcp::endpoint const& ep) m_impl->send_syn(); } +#ifdef TORRENT_UTP_LOG + bool utp_stream::utp_stream_log() { + return log_file_holder.utp_log_file != NULL; + } + + void utp_stream::utp_stream_log(bool enable) { + if (enable) + { + if (log_file_holder.utp_log_file == NULL) + { + log_file_holder.utp_log_file = fopen("utp.log", "w+"); + } + } + else + { + if (log_file_holder.utp_log_file != NULL) + { + FILE* f = log_file_holder.utp_log_file; + log_file_holder.utp_log_file = NULL; + fclose(f); + } + } + } +#endif + // =========== utp_socket_impl ============ utp_socket_impl::~utp_socket_impl() From 12fb68e8e3b59aacc04f090fdfd951ea9a6294d5 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Wed, 12 Aug 2015 21:36:20 -0400 Subject: [PATCH 2/5] Refactor of utp stream logging functions. Renamed utp-stats option to utp-log. --- Jamfile | 4 +-- include/libtorrent/utp_stream.hpp | 13 +++++---- src/utp_stream.cpp | 48 +++++++++++++++---------------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/Jamfile b/Jamfile index ee1a7f276..bc3837fba 100644 --- a/Jamfile +++ b/Jamfile @@ -472,8 +472,8 @@ feature.compose full : TORRENT_EXPENSIVE_INVARIANT_CHE feature disk-stats : off on : composite propagated link-incompatible ; feature.compose on : TORRENT_DISK_STATS ; -feature utp-stats : off on : composite propagated link-incompatible ; -feature.compose on : TORRENT_UTP_LOG TORRENT_VERBOSE_UTP_LOG ; +feature utp-log : off on : composite propagated link-incompatible ; +feature.compose on : TORRENT_UTP_LOG TORRENT_VERBOSE_UTP_LOG ; feature simulate-slow-read : off on : composite propagated ; feature.compose on : TORRENT_SIMULATE_SLOW_READ ; diff --git a/include/libtorrent/utp_stream.hpp b/include/libtorrent/utp_stream.hpp index f9473af71..4c97f176f 100644 --- a/include/libtorrent/utp_stream.hpp +++ b/include/libtorrent/utp_stream.hpp @@ -55,6 +55,14 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { + +#ifdef TORRENT_UTP_LOG + bool is_utp_stream_logging(); + + // This function should be used at the very beginning and very end of your program. + void set_utp_stream_logging(bool enable); +#endif + struct utp_socket_manager; // internal: some MTU and protocol header sizes constants @@ -468,11 +476,6 @@ public: issue_write(); } -#ifdef TORRENT_UTP_LOG - static bool utp_stream_log(); - static void utp_stream_log(bool enable); -#endif - private: // explicitly disallow assignment, to silence msvc warning utp_stream& operator=(utp_stream const&); diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index f5b444a39..285120f5a 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -88,6 +88,29 @@ void utp_log(char const* fmt, ...) va_end(l); } +bool is_utp_stream_logging() { + return log_file_holder.utp_log_file != NULL; +} + +void set_utp_stream_logging(bool enable) { + if (enable) + { + if (log_file_holder.utp_log_file == NULL) + { + log_file_holder.utp_log_file = fopen("utp.log", "w+"); + } + } + else + { + if (log_file_holder.utp_log_file != NULL) + { + FILE* f = log_file_holder.utp_log_file; + log_file_holder.utp_log_file = NULL; + fclose(f); + } + } +} + #define UTP_LOG utp_log #if TORRENT_VERBOSE_UTP_LOG #define UTP_LOGV utp_log @@ -1171,31 +1194,6 @@ void utp_stream::do_connect(tcp::endpoint const& ep) m_impl->send_syn(); } -#ifdef TORRENT_UTP_LOG - bool utp_stream::utp_stream_log() { - return log_file_holder.utp_log_file != NULL; - } - - void utp_stream::utp_stream_log(bool enable) { - if (enable) - { - if (log_file_holder.utp_log_file == NULL) - { - log_file_holder.utp_log_file = fopen("utp.log", "w+"); - } - } - else - { - if (log_file_holder.utp_log_file != NULL) - { - FILE* f = log_file_holder.utp_log_file; - log_file_holder.utp_log_file = NULL; - fclose(f); - } - } - } -#endif - // =========== utp_socket_impl ============ utp_socket_impl::~utp_socket_impl() From 7d111989113727b87480c4ab09df5d7b5896d9d7 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Wed, 12 Aug 2015 21:47:24 -0400 Subject: [PATCH 3/5] Fixed definition of utp log macros. --- Jamfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jamfile b/Jamfile index bc3837fba..e7ac7cd9c 100644 --- a/Jamfile +++ b/Jamfile @@ -473,7 +473,8 @@ feature disk-stats : off on : composite propagated link-incompatible ; feature.compose on : TORRENT_DISK_STATS ; feature utp-log : off on : composite propagated link-incompatible ; -feature.compose on : TORRENT_UTP_LOG TORRENT_VERBOSE_UTP_LOG ; +feature.compose off : TORRENT_UTP_LOG=0 TORRENT_VERBOSE_UTP_LOG=0 ; +feature.compose on : TORRENT_UTP_LOG=1 TORRENT_VERBOSE_UTP_LOG=1 ; feature simulate-slow-read : off on : composite propagated ; feature.compose on : TORRENT_SIMULATE_SLOW_READ ; From 9e29eb997818f01fde5b47cbaae66c777c09410b Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Wed, 12 Aug 2015 23:00:28 -0400 Subject: [PATCH 4/5] Introduced TORRENT_UTP_LOG_ENABLE macro to guarantee that TORRENT_UTP_LOG and TORRENT_VERBOSE_UTP_LOG are always defined (no need to change a lot of macro if). --- Jamfile | 3 +-- include/libtorrent/utp_stream.hpp | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Jamfile b/Jamfile index e7ac7cd9c..963d6cd77 100644 --- a/Jamfile +++ b/Jamfile @@ -473,8 +473,7 @@ feature disk-stats : off on : composite propagated link-incompatible ; feature.compose on : TORRENT_DISK_STATS ; feature utp-log : off on : composite propagated link-incompatible ; -feature.compose off : TORRENT_UTP_LOG=0 TORRENT_VERBOSE_UTP_LOG=0 ; -feature.compose on : TORRENT_UTP_LOG=1 TORRENT_VERBOSE_UTP_LOG=1 ; +feature.compose on : TORRENT_UTP_LOG_ENABLE ; feature simulate-slow-read : off on : composite propagated ; feature.compose on : TORRENT_SIMULATE_SLOW_READ ; diff --git a/include/libtorrent/utp_stream.hpp b/include/libtorrent/utp_stream.hpp index 4c97f176f..7105fbda6 100644 --- a/include/libtorrent/utp_stream.hpp +++ b/include/libtorrent/utp_stream.hpp @@ -55,6 +55,13 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { +#ifndef TORRENT_UTP_LOG_ENABLE + #define TORRENT_UTP_LOG 0 + #define TORRENT_VERBOSE_UTP_LOG 0 +#else + #define TORRENT_UTP_LOG 1 + #define TORRENT_VERBOSE_UTP_LOG 1 +#endif #ifdef TORRENT_UTP_LOG bool is_utp_stream_logging(); From d60ddf6786a649beb7ed76fbd3cf2dc42896727b Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Thu, 13 Aug 2015 00:19:41 -0400 Subject: [PATCH 5/5] Minor change: #ifdef -> #if --- include/libtorrent/utp_stream.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/libtorrent/utp_stream.hpp b/include/libtorrent/utp_stream.hpp index 7105fbda6..2c05f81a7 100644 --- a/include/libtorrent/utp_stream.hpp +++ b/include/libtorrent/utp_stream.hpp @@ -63,7 +63,7 @@ namespace libtorrent #define TORRENT_VERBOSE_UTP_LOG 1 #endif -#ifdef TORRENT_UTP_LOG +#if TORRENT_UTP_LOG bool is_utp_stream_logging(); // This function should be used at the very beginning and very end of your program.