diff --git a/libtorrent/include/libtorrent/assert.hpp b/libtorrent/include/libtorrent/assert.hpp index 62425809e..6577acc46 100644 --- a/libtorrent/include/libtorrent/assert.hpp +++ b/libtorrent/include/libtorrent/assert.hpp @@ -33,12 +33,14 @@ POSSIBILITY OF SUCH DAMAGE. #include #ifndef NDEBUG -#if defined __linux__ && defined __GNUC__ +#if (defined __linux__ || defined __MACH__) && defined __GNUC__ #ifdef assert #undef assert #endif -void assert_fail(const char* expr, int line, char const* file, char const* function); +#include "libtorrent/config.hpp" + +TORRENT_EXPORT void assert_fail(const char* expr, int line, char const* file, char const* function); #define assert(x) if (x) {} else assert_fail(#x, __LINE__, __FILE__, __PRETTY_FUNCTION__) diff --git a/libtorrent/include/libtorrent/config.hpp b/libtorrent/include/libtorrent/config.hpp index 1281ab84c..b36d4da22 100755 --- a/libtorrent/include/libtorrent/config.hpp +++ b/libtorrent/include/libtorrent/config.hpp @@ -34,7 +34,6 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_CONFIG_HPP_INCLUDED #include -#include "libtorrent/assert.hpp" #if defined(__GNUC__) && __GNUC__ >= 4 diff --git a/libtorrent/include/libtorrent/disk_io_thread.hpp b/libtorrent/include/libtorrent/disk_io_thread.hpp index e9103b9e4..61ca9bc53 100644 --- a/libtorrent/include/libtorrent/disk_io_thread.hpp +++ b/libtorrent/include/libtorrent/disk_io_thread.hpp @@ -30,6 +30,10 @@ POSSIBILITY OF SUCH DAMAGE. */ +#ifdef TORRENT_DISK_STATS +#include +#endif + #include "libtorrent/storage.hpp" #include #include @@ -122,6 +126,10 @@ namespace libtorrent int m_block_size; #endif +#ifdef TORRENT_DISK_STATS + std::ofstream m_log; +#endif + // thread for performing blocking disk io operations boost::thread m_disk_io_thread; }; diff --git a/libtorrent/include/libtorrent/intrusive_ptr_base.hpp b/libtorrent/include/libtorrent/intrusive_ptr_base.hpp index ed6944ebb..d2c35ffe3 100644 --- a/libtorrent/include/libtorrent/intrusive_ptr_base.hpp +++ b/libtorrent/include/libtorrent/intrusive_ptr_base.hpp @@ -42,7 +42,7 @@ namespace libtorrent template struct intrusive_ptr_base { - intrusive_ptr_base(const intrusive_ptr_base& b) + intrusive_ptr_base(intrusive_ptr_base const&) : m_refs(0) {} friend void intrusive_ptr_add_ref(intrusive_ptr_base const* s) diff --git a/libtorrent/src/Makefile.am b/libtorrent/src/Makefile.am index 671cb75e5..3ab9f73bd 100644 --- a/libtorrent/src/Makefile.am +++ b/libtorrent/src/Makefile.am @@ -13,7 +13,7 @@ kademlia/traversal_algorithm.cpp endif libtorrent_la_SOURCES = entry.cpp escape_string.cpp \ -enum_net.cpp broadcast_socket.cpp \ +assert.cpp enum_net.cpp broadcast_socket.cpp \ peer_connection.cpp bt_peer_connection.cpp web_peer_connection.cpp \ natpmp.cpp piece_picker.cpp policy.cpp session.cpp session_impl.cpp sha1.cpp \ stat.cpp storage.cpp torrent.cpp torrent_handle.cpp pe_crypto.cpp \ @@ -28,6 +28,7 @@ $(kademlia_sources) noinst_HEADERS = \ $(top_srcdir)/include/libtorrent/alert.hpp \ $(top_srcdir)/include/libtorrent/alert_types.hpp \ +$(top_srcdir)/include/libtorrent/assert.hpp \ $(top_srcdir)/include/libtorrent/aux_/session_impl.hpp \ $(top_srcdir)/include/libtorrent/bandwidth_manager.hpp \ $(top_srcdir)/include/libtorrent/bencode.hpp \ diff --git a/libtorrent/src/assert.cpp b/libtorrent/src/assert.cpp index da79a745b..b4f011978 100644 --- a/libtorrent/src/assert.cpp +++ b/libtorrent/src/assert.cpp @@ -34,7 +34,10 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include +#if defined __linux__ && defined __GNUC__ #include +#endif void assert_fail(char const* expr, int line, char const* file, char const* function) { @@ -48,6 +51,7 @@ void assert_fail(char const* expr, int line, char const* file, char const* funct "expression: %s\n" "stack:\n", file, line, function, expr); +#if defined __linux__ && defined __GNUC__ void* stack[50]; int size = backtrace(stack, 50); char** symbols = backtrace_symbols(stack, size); @@ -58,7 +62,11 @@ void assert_fail(char const* expr, int line, char const* file, char const* funct } free(symbols); - exit(1); +#endif + // send SIGINT to the current process + // to break into the debugger + raise(SIGINT); + abort(); } #endif diff --git a/libtorrent/src/disk_io_thread.cpp b/libtorrent/src/disk_io_thread.cpp index 9096cff0e..4fb2cfb3a 100644 --- a/libtorrent/src/disk_io_thread.cpp +++ b/libtorrent/src/disk_io_thread.cpp @@ -34,6 +34,24 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "libtorrent/disk_io_thread.hpp" +#ifdef TORRENT_DISK_STATS + +#include "libtorrent/time.hpp" +#include + +namespace +{ + std::string log_time() + { + using namespace libtorrent; + static ptime start = time_now(); + return boost::lexical_cast( + total_milliseconds(time_now() - start)); + } +} + +#endif + namespace libtorrent { @@ -45,7 +63,12 @@ namespace libtorrent , m_block_size(block_size) #endif , m_disk_io_thread(boost::ref(*this)) - {} + { + +#ifdef TORRENT_DISK_STATS + m_log.open("disk_io_thread.log", std::ios::trunc); +#endif + } disk_io_thread::~disk_io_thread() { @@ -172,6 +195,9 @@ namespace libtorrent { for (;;) { +#ifdef TORRENT_DISK_STATS + m_log << log_time() << " idle" << std::endl; +#endif boost::mutex::scoped_lock l(m_mutex); while (m_jobs.empty() && !m_abort) m_signal.wait(l); @@ -189,10 +215,16 @@ namespace libtorrent bool free_buffer = true; try { +#ifdef TORRENT_DISK_STATS + ptime start = time_now(); +#endif // std::cerr << "DISK THREAD: executing job: " << j.action << std::endl; switch (j.action) { case disk_io_job::read: +#ifdef TORRENT_DISK_STATS + m_log << log_time() << " read " << j.buffer_size << std::endl; +#endif if (j.buffer == 0) { l.lock(); @@ -217,6 +249,9 @@ namespace libtorrent // usleep(300); break; case disk_io_job::write: +#ifdef TORRENT_DISK_STATS + m_log << log_time() << " write " << j.buffer_size << std::endl; +#endif assert(j.buffer); assert(j.buffer_size <= m_block_size); j.storage->write_impl(j.buffer, j.piece, j.offset @@ -227,16 +262,25 @@ namespace libtorrent break; case disk_io_job::hash: { +#ifdef TORRENT_DISK_STATS + m_log << log_time() << " hash" << std::endl; +#endif sha1_hash h = j.storage->hash_for_piece_impl(j.piece); j.str.resize(20); std::memcpy(&j.str[0], &h[0], 20); } break; case disk_io_job::move_storage: +#ifdef TORRENT_DISK_STATS + m_log << log_time() << " move" << std::endl; +#endif ret = j.storage->move_storage_impl(j.str) ? 1 : 0; j.str = j.storage->save_path().string(); break; case disk_io_job::release_files: +#ifdef TORRENT_DISK_STATS + m_log << log_time() << " release" << std::endl; +#endif j.storage->release_files_impl(); break; } diff --git a/libtorrent/src/peer_connection.cpp b/libtorrent/src/peer_connection.cpp index 7832b4444..59031cc18 100755 --- a/libtorrent/src/peer_connection.cpp +++ b/libtorrent/src/peer_connection.cpp @@ -2915,11 +2915,6 @@ namespace libtorrent // TODO: the timeout should be called by an event INVARIANT_CHECK; -#ifndef NDEBUG - // allow step debugging without timing out - return false; -#endif - ptime now(time_now()); // if the socket is still connecting, don't @@ -2933,6 +2928,10 @@ namespace libtorrent d = now - m_last_receive; if (d > seconds(m_timeout)) return true; + // if it takes more than 5 seconds to receive + // handshake, disconnect + if (in_handshake() && d > seconds(5)) return true; + // disconnect peers that we unchoked, but // they didn't send a request within 20 seconds. // but only if we're a seed diff --git a/libtorrent/src/piece_picker.cpp b/libtorrent/src/piece_picker.cpp index b8121fc86..398573d33 100755 --- a/libtorrent/src/piece_picker.cpp +++ b/libtorrent/src/piece_picker.cpp @@ -1478,7 +1478,7 @@ namespace libtorrent k = std::find(backup_blocks.begin() , backup_blocks.end(), piece_block(i->index, j)); - if (k != interesting_blocks.end()) continue; + if (k != backup_blocks.end()) continue; std::cerr << "interesting blocks:" << std::endl; for (k = interesting_blocks.begin(); k != interesting_blocks.end(); ++k) @@ -1911,4 +1911,3 @@ namespace libtorrent } - diff --git a/libtorrent/src/upnp.cpp b/libtorrent/src/upnp.cpp index 043cf4b94..417521c19 100644 --- a/libtorrent/src/upnp.cpp +++ b/libtorrent/src/upnp.cpp @@ -258,7 +258,7 @@ try { #ifdef TORRENT_UPNP_LOGGING m_log << time_now_string() - << " <== Rootdevice responded with incorrect HTTP packet. Ignoring device" << std::endl; + << " <== Rootdevice responded with incorrect HTTP packet. Ignoring device (" << e.what() << ")" << std::endl; #endif return; } @@ -759,23 +759,9 @@ void upnp::on_upnp_map_response(asio::error_code const& e m_devices.erase(d); return; } - - if (p.status_code() != 200) - { -#ifdef TORRENT_UPNP_LOGGING - m_log << time_now_string() - << " <== error while adding portmap: " << p.status_code() << " " << p.message() << std::endl; -#endif - for (int i = 0; i < num_mappings; ++i) - { - if (d.mapping[i].need_update) - { - map_port(d, i); - return; - } - } - return; - } + + // We don't want to ignore responses with return codes other than 200 + // since those might contain valid UPnP error codes error_code_parse_state s; xml_parse((char*)p.get_body().begin, (char*)p.get_body().end