From 6d7e9e45214a2ca196b16458aede75305927c64f Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 12 Oct 2012 04:50:34 +0000 Subject: [PATCH] remove some iostream dependencies --- include/libtorrent/lazy_entry.hpp | 4 -- src/bt_peer_connection.cpp | 2 +- src/lazy_bdecode.cpp | 7 ---- src/logger.cpp | 2 +- src/storage.cpp | 69 ------------------------------- src/torrent.cpp | 38 +++++++---------- test/test_bencoding.cpp | 16 ++----- 7 files changed, 20 insertions(+), 118 deletions(-) diff --git a/include/libtorrent/lazy_entry.hpp b/include/libtorrent/lazy_entry.hpp index 4c76d26bc..53f8c4b45 100644 --- a/include/libtorrent/lazy_entry.hpp +++ b/include/libtorrent/lazy_entry.hpp @@ -284,10 +284,6 @@ namespace libtorrent TORRENT_EXPORT std::string print_entry(lazy_entry const& e , bool single_line = false, int indent = 0); -#if TORRENT_USE_IOSTREAM - TORRENT_EXPORT std::ostream& operator<<(std::ostream& os, lazy_entry const& e); -#endif - } diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 2954ad117..a42fe8aa9 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -2179,7 +2179,7 @@ namespace libtorrent send_buffer(msg, sizeof(msg)); send_buffer(&dict_msg[0], dict_msg.size()); -#if defined TORRENT_VERBOSE_LOGGING && TORRENT_USE_IOSTREAM +#if defined TORRENT_VERBOSE_LOGGING std::stringstream handshake_str; handshake.print(handshake_str); peer_log("==> EXTENDED HANDSHAKE: %s", handshake_str.str().c_str()); diff --git a/src/lazy_bdecode.cpp b/src/lazy_bdecode.cpp index cf28ce4b2..9b1d9950c 100644 --- a/src/lazy_bdecode.cpp +++ b/src/lazy_bdecode.cpp @@ -426,13 +426,6 @@ namespace libtorrent return return_t(m_begin, m_len); } -#if TORRENT_USE_IOSTREAM - std::ostream& operator<<(std::ostream& os, lazy_entry const& e) - { - return os << print_entry(e); - } -#endif // TORRENT_USE_IOSTREAM - int line_longer_than(lazy_entry const& e, int limit) { int line_len = 0; diff --git a/src/logger.cpp b/src/logger.cpp index 48b69d840..2a512dc5e 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -89,7 +89,7 @@ namespace virtual bool on_extension_handshake(lazy_entry const& h) { log_timestamp(); - m_file << "<== EXTENSION_HANDSHAKE\n" << h; + m_file << "<== EXTENSION_HANDSHAKE\n" << print_entry(h); return true; } diff --git a/src/storage.cpp b/src/storage.cpp index 6e2936703..fdb0db96b 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -71,12 +71,6 @@ POSSIBILITY OF SUCH DAMAGE. //#define TORRENT_PARTIAL_HASH_LOG -#if TORRENT_USE_IOSTREAM -#include -#include -#include -#endif - #if defined(__APPLE__) // for getattrlist() #include @@ -99,20 +93,6 @@ POSSIBILITY OF SUCH DAMAGE. // for convert_to_wstring and convert_to_native #include "libtorrent/escape_string.hpp" -#if defined TORRENT_DEBUG && defined TORRENT_STORAGE_DEBUG && TORRENT_USE_IOSTREAM -namespace -{ - using namespace libtorrent; - - void print_to_log(std::string const& s) - { - static std::ofstream log("log.txt"); - log << s; - log.flush(); - } -} -#endif - namespace libtorrent { std::vector > get_filesizes( @@ -1805,10 +1785,6 @@ ret: if (m_storage->settings().disable_hash_checks) return ret; -#if defined TORRENT_PARTIAL_HASH_LOG && TORRENT_USE_IOSTREAM - std::ofstream out("partial_hash.log", std::ios::app); -#endif - if (offset == 0) { partial_hash& ph = m_piece_hasher[piece_index]; @@ -1818,15 +1794,6 @@ ret: for (file::iovec_t* i = iov, *end(iov + num_bufs); i < end; ++i) ph.h.update((char const*)i->iov_base, i->iov_len); -#if defined TORRENT_PARTIAL_HASH_LOG && TORRENT_USE_IOSTREAM - out << time_now_string() << " NEW [" - " s: " << this - << " p: " << piece_index - << " off: " << offset - << " size: " << size - << " entries: " << m_piece_hasher.size() - << " ]" << std::endl; -#endif } else { @@ -2849,24 +2816,6 @@ ret: if (slot_index != piece_index && m_slot_to_piece[piece_index] >= 0) { - -#if defined TORRENT_DEBUG && defined TORRENT_STORAGE_DEBUG && TORRENT_USE_IOSTREAM - std::stringstream s; - - s << "there is another piece at our slot, swapping.."; - - s << "\n piece_index: "; - s << piece_index; - s << "\n slot_index: "; - s << slot_index; - s << "\n piece at our slot: "; - s << m_slot_to_piece[piece_index]; - s << "\n"; - - print_to_log(s.str()); - debug_log(); -#endif - int piece_at_our_slot = m_slot_to_piece[piece_index]; TORRENT_ASSERT(m_piece_to_slot[piece_at_our_slot] == piece_index); @@ -3090,24 +3039,6 @@ ret: } } -#if defined(TORRENT_STORAGE_DEBUG) && TORRENT_USE_IOSTREAM - void piece_manager::debug_log() const - { - std::stringstream s; - - s << "index\tslot\tpiece\n"; - - for (int i = 0; i < m_files.num_pieces(); ++i) - { - s << i << "\t" << m_slot_to_piece[i] << "\t"; - s << m_piece_to_slot[i] << "\n"; - } - - s << "---------------------------------\n"; - - print_to_log(s.str()); - } -#endif #endif } // namespace libtorrent diff --git a/src/torrent.cpp b/src/torrent.cpp index 000b3a2de..b13694f0e 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -38,10 +38,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#ifdef TORRENT_DEBUG -#include -#endif - #ifdef _MSC_VER #pragma warning(push, 1) #endif @@ -95,10 +91,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/struct_debug.hpp" #endif -#if TORRENT_USE_IOSTREAM -#include -#endif - using namespace libtorrent; using boost::tuples::tuple; using boost::tuples::get; @@ -2575,25 +2567,23 @@ namespace libtorrent if (complete >= 0 && incomplete >= 0) m_last_scrape = 0; -#if (defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING) && TORRENT_USE_IOSTREAM - std::stringstream s; - s << "TRACKER RESPONSE:\n" - "interval: " << interval << "\n" - "peers:\n"; +#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING + debug_log("TRACKER RESPONSE\n" + "interval: %d\n" + "external ip: %s\n" + "we connected to: %s\n" + "peers:" + , interval + , print_address(external_ip).c_str() + , print_address(tracker_ip).c_str()); + for (std::vector::const_iterator i = peer_list.begin(); i != peer_list.end(); ++i) { - s << " " << std::setfill(' ') << std::setw(16) << i->ip - << " " << std::setw(5) << std::dec << i->port << " "; - if (!i->pid.is_all_zeros()) s << " " << i->pid << " " << identify_client(i->pid); - s << "\n"; + debug_log(" %16s %5d %s %s", i->ip.c_str(), i->port + , i->pid.is_all_zeros()?"":to_hex(i->pid.to_string()).c_str() + , identify_client(i->pid).c_str()); } - s << "external ip: " << external_ip << "\n"; - s << "tracker ips: "; - std::copy(tracker_ips.begin(), tracker_ips.end(), std::ostream_iterator
(s, " ")); - s << "\n"; - s << "we connected to: " << tracker_ip << "\n"; - debug_log("%s", s.str().c_str()); #endif // for each of the peers we got from the tracker for (std::vector::iterator i = peer_list.begin(); @@ -2689,7 +2679,7 @@ namespace libtorrent ?m_ses.m_ipv6_interface.address() :m_ses.m_ipv4_interface.address(); announce_with_tracker(r.event, bind_interface); -#if (defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING) && TORRENT_USE_IOSTREAM +#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING debug_log("announce again using %s as the bind interface" , print_address(bind_interface).c_str()); #endif diff --git a/test/test_bencoding.cpp b/test/test_bencoding.cpp index d51841754..bf484090b 100644 --- a/test/test_bencoding.cpp +++ b/test/test_bencoding.cpp @@ -110,9 +110,7 @@ int test_main() error_code ec; int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec); TORRENT_ASSERT(ret == 0); -#if TORRENT_USE_IOSTREAM - std::cout << e << std::endl; -#endif + printf("%s\n", print_entry(e).c_str()); std::pair section = e.data_section(); TORRENT_ASSERT(std::memcmp(b, section.first, section.second) == 0); TORRENT_ASSERT(section.second == sizeof(b) - 1); @@ -126,9 +124,7 @@ int test_main() error_code ec; int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec); TORRENT_ASSERT(ret == 0); -#if TORRENT_USE_IOSTREAM - std::cout << e << std::endl; -#endif + printf("%s\n", print_entry(e).c_str()); std::pair section = e.data_section(); TORRENT_ASSERT(std::memcmp(b, section.first, section.second) == 0); TORRENT_ASSERT(section.second == sizeof(b) - 1); @@ -143,9 +139,7 @@ int test_main() error_code ec; int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec); TORRENT_ASSERT(ret == 0); -#if TORRENT_USE_IOSTREAM - std::cout << e << std::endl; -#endif + printf("%s\n", print_entry(e).c_str()); std::pair section = e.data_section(); TORRENT_ASSERT(std::memcmp(b, section.first, section.second) == 0); TORRENT_ASSERT(section.second == sizeof(b) - 1); @@ -167,9 +161,7 @@ int test_main() error_code ec; int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec); TORRENT_ASSERT(ret == 0); -#if TORRENT_USE_IOSTREAM - std::cout << e << std::endl; -#endif + printf("%s\n", print_entry(e).c_str()); std::pair section = e.data_section(); TORRENT_ASSERT(std::memcmp(b, section.first, section.second) == 0); TORRENT_ASSERT(section.second == sizeof(b) - 1);