remove some iostream dependencies

This commit is contained in:
Arvid Norberg 2012-10-12 04:50:34 +00:00
parent 8f0d039b3c
commit 6d7e9e4521
7 changed files with 20 additions and 118 deletions

View File

@ -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
}

View File

@ -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());

View File

@ -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;

View File

@ -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;
}

View File

@ -71,12 +71,6 @@ POSSIBILITY OF SUCH DAMAGE.
//#define TORRENT_PARTIAL_HASH_LOG
#if TORRENT_USE_IOSTREAM
#include <ios>
#include <iostream>
#include <iomanip>
#endif
#if defined(__APPLE__)
// for getattrlist()
#include <sys/attr.h>
@ -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<std::pair<size_type, std::time_t> > 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

View File

@ -38,10 +38,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <cctype>
#include <numeric>
#ifdef TORRENT_DEBUG
#include <iostream>
#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 <iostream>
#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<peer_entry>::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<address>(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<peer_entry>::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

View File

@ -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<const char*, int> 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<const char*, int> 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<const char*, int> 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<const char*, int> section = e.data_section();
TORRENT_ASSERT(std::memcmp(b, section.first, section.second) == 0);
TORRENT_ASSERT(section.second == sizeof(b) - 1);