Merge pull request #83 from aldenml/utp-stream-log

Added utp-stats bjam option to enable utp stream log (utp.log file).
This commit is contained in:
Arvid Norberg 2015-08-13 20:53:19 -04:00
commit f73d1a95dc
3 changed files with 44 additions and 4 deletions

View File

@ -472,6 +472,9 @@ feature.compose <invariant-checks>full : <define>TORRENT_EXPENSIVE_INVARIANT_CHE
feature disk-stats : off on : composite propagated link-incompatible ;
feature.compose <disk-stats>on : <define>TORRENT_DISK_STATS ;
feature utp-log : off on : composite propagated link-incompatible ;
feature.compose <utp-log>on : <define>TORRENT_UTP_LOG_ENABLE ;
feature simulate-slow-read : off on : composite propagated ;
feature.compose <simulate-slow-read>on : <define>TORRENT_SIMULATE_SLOW_READ ;

View File

@ -55,6 +55,21 @@ 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
#if 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

View File

@ -44,9 +44,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/cstdint.hpp>
#include <limits>
#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));
@ -89,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