From 7645360cf91175ec82cfed4f41175bf6fe793ca1 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 18 Apr 2004 13:41:08 +0000 Subject: [PATCH] *** empty log message *** --- docs/manual.rst | 46 ++++++++++++++++++++++++++++++++++ include/libtorrent/torrent.hpp | 2 +- src/session.cpp | 26 +++++++++++++++---- src/torrent.cpp | 4 +-- 4 files changed, 70 insertions(+), 8 deletions(-) diff --git a/docs/manual.rst b/docs/manual.rst index 17ef9f7b0..ac33eabf1 100755 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -230,6 +230,8 @@ The ``session`` class has the following synopsis:: void set_upload_rate_limit(int bytes_per_second); void set_download_rate_limit(int bytes_per_second); + session_status status() const; + bool is_listening() const; unsigned short listen_port() const; bool listen_on( @@ -328,6 +330,50 @@ you don't want to limit upload rate, you can set this to -1 (the default). of upload rate. +status() +-------- + + :: + + session_status status() const; + +``status()`` returns session wide statistics and status. The ``session_status`` +struct has the following members:: + + struct session_status + { + bool has_incoming_connections; + + float upload_rate; + float download_rate; + + float payload_upload_rate; + float payload_download_rate; + + size_type total_download; + size_type total_upload; + + size_type total_payload_download; + size_type total_payload_upload; + + int num_peers; + }; + +``has_incoming_connections`` is false as long as no incoming connections has been +established on the listening socket. Every time you change the listen port, this will +be reset to false. + +``upload_rate``, ``download_rate``, ``payload_download_rate`` and ``payload_upload_rate`` +are the total download and upload rates accumulated from all torrents. The payload +versions is the payload download only. + +``total_download`` and ``total_upload`` are the total number of bytes downloaded and +uploaded to and from all torrents. ``total_payload_download`` and ``total_payload_upload`` +are the same thing but where only the payload is considered. + +``num_peers`` is the total number of peer connections this session have. + + is_listening() listen_port() listen_on() ---------------------------------------- diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 24816495b..b079e0d0a 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -103,7 +103,7 @@ namespace libtorrent // caclulate the upload/download and number // of connections this torrent needs. And prepare // it for being used by allocate_resources. - void second_tick(); + void second_tick(stat& accumulator); // debug purpose only void print(std::ostream& os) const; diff --git a/src/session.cpp b/src/session.cpp index 0130359f3..efe5b9437 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -636,10 +636,7 @@ namespace libtorrent { namespace detail } // tick() will set the used upload quota - i->second->second_tick(); - - // accumulate the statistics from all torrents - m_stat += i->second->statistics(); + i->second->second_tick(m_stat); ++i; } purge_connections(); @@ -898,6 +895,8 @@ namespace libtorrent m_impl.m_listen_socket.reset(); } + m_impl.m_incoming_connection = false; + m_impl.m_listen_port_range = port_range; m_impl.m_listen_interface = address(net_interface, port_range.first); m_impl.open_listen_port(); @@ -913,7 +912,24 @@ namespace libtorrent session_status session::status() const { session_status s; -// TODO: implement + s.has_incoming_connections = m_impl.m_incoming_connection; + s.num_peers = (int)m_impl.m_connections.size(); + + s.download_rate = m_impl.m_stat.download_rate(); + s.upload_rate = m_impl.m_stat.upload_rate(); + + s.payload_download_rate = m_impl.m_stat.download_payload_rate(); + s.payload_upload_rate = m_impl.m_stat.upload_payload_rate(); + + s.total_download = m_impl.m_stat.total_protocol_download() + + m_impl.m_stat.total_payload_download(); + + s.total_upload = m_impl.m_stat.total_protocol_upload() + + m_impl.m_stat.total_payload_upload(); + + s.total_payload_download = m_impl.m_stat.total_payload_download(); + s.total_payload_upload = m_impl.m_stat.total_payload_upload(); + return s; } diff --git a/src/torrent.cpp b/src/torrent.cpp index b510352ce..a3cfb5f8e 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -647,7 +647,7 @@ namespace libtorrent m_time_scaler = 0; } - void torrent::second_tick() + void torrent::second_tick(stat& accumulator) { if (m_paused) return; @@ -672,7 +672,6 @@ namespace libtorrent { peer_connection* p = i->second; m_stat += p->statistics(); - // updates the peer connection's ul/dl bandwidth // resource requests p->second_tick(); @@ -698,6 +697,7 @@ namespace libtorrent m_dl_bandwidth_quota.max = std::min(m_dl_bandwidth_quota.max, m_download_bandwidth_limit); + accumulator += m_stat; m_stat.second_tick(); }