libtorrent upnp fix, compilation fix 1577

This commit is contained in:
Marcos Pinto 2007-09-17 19:48:16 +00:00
parent 4fbef5d94a
commit a93c236e0e
10 changed files with 78 additions and 32 deletions

View file

@ -33,12 +33,14 @@ POSSIBILITY OF SUCH DAMAGE.
#include <cassert>
#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__)

View file

@ -34,7 +34,6 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_CONFIG_HPP_INCLUDED
#include <boost/config.hpp>
#include "libtorrent/assert.hpp"
#if defined(__GNUC__) && __GNUC__ >= 4

View file

@ -30,6 +30,10 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef TORRENT_DISK_STATS
#include <fstream>
#endif
#include "libtorrent/storage.hpp"
#include <boost/thread/thread.hpp>
#include <boost/function.hpp>
@ -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;
};

View file

@ -42,7 +42,7 @@ namespace libtorrent
template<class T>
struct intrusive_ptr_base
{
intrusive_ptr_base(const intrusive_ptr_base<T>& b)
intrusive_ptr_base(intrusive_ptr_base<T> const&)
: m_refs(0) {}
friend void intrusive_ptr_add_ref(intrusive_ptr_base<T> const* s)

View file

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

View file

@ -34,7 +34,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#if defined __linux__ && defined __GNUC__
#include <execinfo.h>
#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

View file

@ -34,6 +34,24 @@ POSSIBILITY OF SUCH DAMAGE.
#include <deque>
#include "libtorrent/disk_io_thread.hpp"
#ifdef TORRENT_DISK_STATS
#include "libtorrent/time.hpp"
#include <boost/lexical_cast.hpp>
namespace
{
std::string log_time()
{
using namespace libtorrent;
static ptime start = time_now();
return boost::lexical_cast<std::string>(
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;
}

View file

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

View file

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

View file

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