Refactor of utp stream logging functions.

Renamed utp-stats option to utp-log.
This commit is contained in:
Alden Torres 2015-08-12 21:36:20 -04:00
parent 02afc8b640
commit 12fb68e8e3
3 changed files with 33 additions and 32 deletions

View File

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

View File

@ -55,6 +55,14 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent 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; struct utp_socket_manager;
// internal: some MTU and protocol header sizes constants // internal: some MTU and protocol header sizes constants
@ -468,11 +476,6 @@ public:
issue_write(); issue_write();
} }
#ifdef TORRENT_UTP_LOG
static bool utp_stream_log();
static void utp_stream_log(bool enable);
#endif
private: private:
// explicitly disallow assignment, to silence msvc warning // explicitly disallow assignment, to silence msvc warning
utp_stream& operator=(utp_stream const&); utp_stream& operator=(utp_stream const&);

View File

@ -88,6 +88,29 @@ void utp_log(char const* fmt, ...)
va_end(l); 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 #define UTP_LOG utp_log
#if TORRENT_VERBOSE_UTP_LOG #if TORRENT_VERBOSE_UTP_LOG
#define UTP_LOGV utp_log #define UTP_LOGV utp_log
@ -1171,31 +1194,6 @@ void utp_stream::do_connect(tcp::endpoint const& ep)
m_impl->send_syn(); 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::~utp_socket_impl() utp_socket_impl::~utp_socket_impl()