From 96cedc9b5f7dbb18fcc32c34fa6e36dd60964fff Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 15 Dec 2009 13:11:07 +0000 Subject: [PATCH] more beos fixes --- examples/client_test.cpp | 16 +++++++++++----- include/libtorrent/buffer.hpp | 1 + include/libtorrent/session.hpp | 2 ++ src/allocator.cpp | 13 ++++++++----- test/setup_transfer.cpp | 25 ++++++++++++++----------- test/test.hpp | 16 ++++++++++++++++ test/test_auto_unchoke.cpp | 1 + test/test_dht.cpp | 1 + test/test_fast_extension.cpp | 8 +++++--- test/test_hasher.cpp | 1 + test/test_http_connection.cpp | 4 +++- test/test_lsd.cpp | 1 + test/test_metadata_extension.cpp | 1 + test/test_pex.cpp | 1 + test/test_piece_picker.cpp | 1 + test/test_primitives.cpp | 1 + test/test_storage.cpp | 7 +++++-- test/test_swarm.cpp | 1 + test/test_torrent.cpp | 10 +++++++--- test/test_trackers_extension.cpp | 5 +++-- test/test_transfer.cpp | 3 ++- test/test_upnp.cpp | 4 +++- test/test_web_seed.cpp | 5 +++-- 23 files changed, 92 insertions(+), 36 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 9f98fd888..1d24ec249 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -135,11 +135,12 @@ bool sleep_and_input(char* c, int sleep) FD_ZERO(&set); FD_SET(0, &set); timeval tv = {sleep, 0}; - if (select(1, &set, 0, 0, &tv) > 0) - { - *c = getc(stdin); - return true; - } +// if (select(1, &set, 0, 0, &tv) > 0) +// { +// *c = getc(stdin); +// return true; +// } + libtorrent::sleep(500); return false; } @@ -752,6 +753,11 @@ int main(int argc, char* argv[]) using namespace libtorrent; session_settings settings; + { + mutex m; + mutex::scoped_lock l(m); + } + settings.user_agent = "client_test/" LIBTORRENT_VERSION; settings.auto_upload_slots_rate_based = true; //settings.announce_to_all_trackers = true; diff --git a/include/libtorrent/buffer.hpp b/include/libtorrent/buffer.hpp index d6e197328..26d2a3ab9 100644 --- a/include/libtorrent/buffer.hpp +++ b/include/libtorrent/buffer.hpp @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "libtorrent/invariant_check.hpp" #include "libtorrent/assert.hpp" +#include // malloc/free/realloc namespace libtorrent { diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index 1b89ead78..09dfe3df5 100644 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -188,7 +188,9 @@ namespace libtorrent torrent_handle find_torrent(sha1_hash const& info_hash) const; // all torrent_handles must be destructed before the session is destructed! +#ifndef BOOST_NO_EXCEPTIONS torrent_handle add_torrent(add_torrent_params const& params); +#endif torrent_handle add_torrent(add_torrent_params const& params, error_code& ec); #ifndef TORRENT_NO_DEPRECATE diff --git a/src/allocator.cpp b/src/allocator.cpp index 0995048f4..5b08bf23c 100644 --- a/src/allocator.cpp +++ b/src/allocator.cpp @@ -77,10 +77,11 @@ namespace libtorrent #elif defined TORRENT_WINDOWS return (char*)VirtualAlloc(0, bytes, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); #elif defined TORRENT_BEOS - // we could potentially use create_area() here, but - // you can't free it through its pointer, you need to - // associate the area_id with the pointer somehow - return (char*)::malloc(bytes); + void* ret = 0; + area_id id = create_area("", &ret, B_ANY_ADDRESS + , (bytes + page_size() - 1) & (page_size()-1), B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); + if (id < B_OK) return 0; + return (char*)ret; #else return (char*)valloc(bytes); #endif @@ -91,7 +92,9 @@ namespace libtorrent #ifdef TORRENT_WINDOWS VirtualFree(block, 0, MEM_RELEASE); #elif defined TORRENT_BEOS - return ::free(block); + area_id id = area_for(block); + if (id < B_OK) return; + delete_area(id); #else ::free(block); #endif diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index b7da5a430..fe1487141 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -31,7 +31,6 @@ POSSIBILITY OF SUCH DAMAGE. */ #include -#include #include "libtorrent/session.hpp" #include "libtorrent/hasher.hpp" @@ -45,6 +44,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/assert.hpp" #include "libtorrent/alert_types.hpp" #include "libtorrent/create_torrent.hpp" +#include "libtorrent/socket_io.hpp" // print_endpoint using namespace libtorrent; @@ -55,10 +55,10 @@ void report_failure(char const* err, char const* file, int line) #ifdef TORRENT_WINDOWS HANDLE console = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, 0, CONSOLE_TEXTMODE_BUFFER, 0); SetConsoleTextAttribute(console, FOREGROUND_RED); - std::cerr << "\n**** " << file << ":" << line << " \"" << err << " ****\n\n"; + fprintf(stderr, "\n**** %s:%d \"%s\" ****\n\n", file, line, err); CloseHandle(console); #else - std::cerr << "\033[31m" << file << ":" << line << " \"" << err << "\"\033[0m\n"; + fprintf(stderr, "\033[31m %s:%d \"%s\"\033[0m\n", file, line, err); #endif tests_failure = true; } @@ -79,13 +79,13 @@ bool print_alerts(libtorrent::session& ses, char const* name if (predicate && predicate(a.get())) ret = true; if (peer_disconnected_alert* p = dynamic_cast(a.get())) { - std::cerr << name << "(" << p->ip << "): " << p->message() << "\n"; + fprintf(stderr, "%s(%s): %s\n", name, print_endpoint(p->ip).c_str(), p->message().c_str()); } else if (a->message() != "block downloading" && a->message() != "block finished" && a->message() != "piece finished") { - std::cerr << name << ": " << a->message() << "\n"; + fprintf(stderr, "%s: %s\n", name, p->message().c_str()); } TEST_CHECK(dynamic_cast(a.get()) == 0 || allow_failed_fastresume); @@ -202,7 +202,9 @@ boost::intrusive_ptr create_torrent(std::ostream* file, int piece_ std::back_insert_iterator > out(tmp); bencode(out, t.generate()); - return boost::intrusive_ptr(new torrent_info(&tmp[0], tmp.size())); + error_code ec; + return boost::intrusive_ptr(new torrent_info( + &tmp[0], tmp.size(), ec)); } boost::tuple @@ -254,7 +256,7 @@ setup_transfer(session* ses1, session* ses2, session* ses3 } char ih_hex[41]; to_hex((char const*)&t->info_hash()[0], 20, ih_hex); - std::cerr << "generated torrent: " << ih_hex << " ./tmp1" << suffix << "/temporary" << std::endl; + fprintf(stderr, "generated torrent: %s ./tmp1%s/temporary\n", ih_hex, suffix.c_str()); } else { @@ -269,7 +271,8 @@ setup_transfer(session* ses1, session* ses2, session* ses3 if (p) param = *p; param.ti = clone_ptr(t); param.save_path = "./tmp1" + suffix; - torrent_handle tor1 = ses1->add_torrent(param); + error_code ec; + torrent_handle tor1 = ses1->add_torrent(param, ec); tor1.super_seeding(super_seeding); TEST_CHECK(!ses1->get_torrents().empty()); torrent_handle tor2; @@ -282,7 +285,7 @@ setup_transfer(session* ses1, session* ses2, session* ses3 { param.ti = clone_ptr(t); param.save_path = "./tmp3" + suffix; - tor3 = ses3->add_torrent(param); + tor3 = ses3->add_torrent(param, ec); TEST_CHECK(!ses3->get_torrents().empty()); } @@ -297,7 +300,7 @@ setup_transfer(session* ses1, session* ses2, session* ses3 } param.save_path = "./tmp2" + suffix; - tor2 = ses2->add_torrent(param); + tor2 = ses2->add_torrent(param, ec); TEST_CHECK(!ses2->get_torrents().empty()); assert(ses1->get_torrents().size() == 1); @@ -307,7 +310,7 @@ setup_transfer(session* ses1, session* ses2, session* ses3 if (connect_peers) { - std::cerr << "connecting peer\n"; + fprintf(stderr, "connecting peer\n"); error_code ec; tor1.connect_peer(tcp::endpoint(address::from_string("127.0.0.1", ec) , ses2->listen_port())); diff --git a/test/test.hpp b/test/test.hpp index caa40d8ef..cf3521fe6 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -35,6 +35,10 @@ POSSIBILITY OF SUCH DAMAGE. void report_failure(char const* str, char const* file, int line); +#include +#include +#include + #if defined(_MSC_VER) #define COUNTER_GUARD(x) #else @@ -51,6 +55,17 @@ void report_failure(char const* str, char const* file, int line); #define TEST_REPORT_AUX(x, line, file) \ report_failure(x, line, file) +#ifdef BOOST_NO_EXCEPTIONS +#define TEST_CHECK(x) \ + if (!(x)) \ + TEST_REPORT_AUX("TEST_CHECK failed: \"" #x "\"", __FILE__, __LINE__); +#define TEST_EQUAL(x, y) \ + if (x != y) { \ + std::stringstream s; \ + s << "TEST_EQUAL_ERROR: " << #x << ": " << x << " expected: " << y << std::endl; \ + TEST_REPORT_AUX(s.str().c_str(), __FILE__, __LINE__); \ + } +#else #define TEST_CHECK(x) \ try \ { \ @@ -82,6 +97,7 @@ void report_failure(char const* str, char const* file, int line); { \ TEST_ERROR("Exception thrown: " #x); \ } +#endif #define TEST_ERROR(x) \ TEST_REPORT_AUX((std::string("ERROR: \"") + x + "\"").c_str(), __FILE__, __LINE__) diff --git a/test/test_auto_unchoke.cpp b/test/test_auto_unchoke.cpp index 8b712e1ab..345287eb6 100644 --- a/test/test_auto_unchoke.cpp +++ b/test/test_auto_unchoke.cpp @@ -4,6 +4,7 @@ #include "libtorrent/alert_types.hpp" #include "libtorrent/thread.hpp" #include +#include #include "test.hpp" #include "setup_transfer.hpp" diff --git a/test/test_dht.cpp b/test/test_dht.cpp index 2c7505552..2634d8acb 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/session.hpp" #include "libtorrent/kademlia/node.hpp" // for verify_message #include "libtorrent/bencode.hpp" +#include #include "test.hpp" diff --git a/test/test_fast_extension.cpp b/test/test_fast_extension.cpp index a786f47fa..d9f0aeba8 100644 --- a/test/test_fast_extension.cpp +++ b/test/test_fast_extension.cpp @@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/io.hpp" #include #include +#include using namespace libtorrent; @@ -161,7 +162,8 @@ void test_reject_fast() boost::intrusive_ptr t = ::create_torrent(); sha1_hash ih = t->info_hash(); session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48900, 49000), "0.0.0.0", 0); - ses1.add_torrent(t, "./tmp1_fast"); + error_code ec; + ses1.add_torrent(t, "./tmp1_fast", ec); test_sleep(2000); @@ -218,12 +220,12 @@ void test_respect_suggest() boost::intrusive_ptr t = ::create_torrent(); sha1_hash ih = t->info_hash(); session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48900, 49000), "0.0.0.0", 0); - ses1.add_torrent(t, "./tmp1_fast"); + error_code ec; + ses1.add_torrent(t, "./tmp1_fast", ec); test_sleep(2000); io_service ios; - error_code ec; stream_socket s(ios); s.connect(tcp::endpoint(address::from_string("127.0.0.1", ec), ses1.listen_port()), ec); diff --git a/test/test_hasher.cpp b/test/test_hasher.cpp index 55cc4259f..b11868355 100644 --- a/test/test_hasher.cpp +++ b/test/test_hasher.cpp @@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/hasher.hpp" #include +#include "libtorrent/escape_string.hpp" // from_hex #include "test.hpp" diff --git a/test/test_http_connection.cpp b/test/test_http_connection.cpp index bfa428c0d..69d5ad805 100644 --- a/test/test_http_connection.cpp +++ b/test/test_http_connection.cpp @@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "setup_transfer.hpp" #include +#include #include using namespace libtorrent; @@ -67,7 +68,8 @@ void http_connect_handler(http_connection& c) ++connect_handler_called; TEST_CHECK(c.socket().is_open()); error_code ec; - std::cerr << "connected to: " << c.socket().remote_endpoint(ec) << std::endl; + std::cerr << "connected to: " << print_endpoint(c.socket().remote_endpoint(ec)) + << std::endl; TEST_CHECK(c.socket().remote_endpoint(ec).address() == address::from_string("127.0.0.1", ec)); } diff --git a/test/test_lsd.cpp b/test/test_lsd.cpp index f3dcf4493..613352d07 100644 --- a/test/test_lsd.cpp +++ b/test/test_lsd.cpp @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "test.hpp" #include "setup_transfer.hpp" +#include void test_lsd() { diff --git a/test/test_metadata_extension.cpp b/test/test_metadata_extension.cpp index dd44d68ff..5a54763c5 100644 --- a/test/test_metadata_extension.cpp +++ b/test/test_metadata_extension.cpp @@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "setup_transfer.hpp" #include "libtorrent/extensions/metadata_transfer.hpp" #include "libtorrent/extensions/ut_metadata.hpp" +#include using boost::tuples::ignore; diff --git a/test/test_pex.cpp b/test/test_pex.cpp index 978ebf0f1..edf48ceff 100644 --- a/test/test_pex.cpp +++ b/test/test_pex.cpp @@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "test.hpp" #include "setup_transfer.hpp" +#include void test_pex() { diff --git a/test/test_piece_picker.cpp b/test/test_piece_picker.cpp index 1d05515ee..b8dfccc5a 100644 --- a/test/test_piece_picker.cpp +++ b/test/test_piece_picker.cpp @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include "test.hpp" diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp index b54633877..50e937012 100644 --- a/test/test_primitives.cpp +++ b/test/test_primitives.cpp @@ -52,6 +52,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include "test.hpp" diff --git a/test/test_storage.cpp b/test/test_storage.cpp index 0fcc3caa0..7959504fa 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -43,6 +43,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "test.hpp" #include "setup_transfer.hpp" +#include +#include using namespace libtorrent; @@ -732,7 +734,8 @@ void test_fastresume(std::string const& test_path) session ses(fingerprint(" ", 0,0,0,0), 0); ses.set_alert_mask(alert::all_categories); - torrent_handle h = ses.add_torrent(boost::intrusive_ptr(new torrent_info(*t)) + error_code ec; + torrent_handle h = ses.add_torrent(boost::intrusive_ptr(new torrent_info(*t), ec) , combine_path(test_path, "tmp1"), entry(), storage_mode_compact); for (int i = 0; i < 10; ++i) @@ -804,7 +807,7 @@ void test_rename_file_in_fastresume(std::string const& test_path) session ses(fingerprint(" ", 0,0,0,0), 0); ses.set_alert_mask(alert::all_categories); - torrent_handle h = ses.add_torrent(boost::intrusive_ptr(new torrent_info(*t)) + torrent_handle h = ses.add_torrent(boost::intrusive_ptr(new torrent_info(*t, ec)) , combine_path(test_path, "tmp2"), entry() , storage_mode_compact); diff --git a/test/test_swarm.cpp b/test/test_swarm.cpp index 451dbeac2..e141d0849 100644 --- a/test/test_swarm.cpp +++ b/test/test_swarm.cpp @@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "test.hpp" #include "setup_transfer.hpp" +#include void test_swarm(bool super_seeding = false, bool strict = false, bool seed_mode = false, bool time_critical = false) { diff --git a/test/test_torrent.cpp b/test/test_torrent.cpp index 6520d1113..d6900da62 100644 --- a/test/test_torrent.cpp +++ b/test/test_torrent.cpp @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/alert_types.hpp" #include "libtorrent/thread.hpp" #include +#include #include "test.hpp" #include "setup_transfer.hpp" @@ -52,7 +53,8 @@ void test_running_torrent(boost::intrusive_ptr info, size_type fil add_torrent_params p; p.ti = info; p.save_path = "."; - torrent_handle h = ses.add_torrent(p); + error_code ec; + torrent_handle h = ses.add_torrent(p, ec); test_sleep(500); torrent_status st = h.status(); @@ -151,7 +153,8 @@ int test_main() std::vector tmp; std::back_insert_iterator > out(tmp); bencode(out, t.generate()); - boost::intrusive_ptr info(new torrent_info(&tmp[0], tmp.size())); + error_code ec; + boost::intrusive_ptr info(new torrent_info(&tmp[0], tmp.size(), ec)); TEST_CHECK(info->num_pieces() > 0); test_running_torrent(info, file_size); @@ -167,7 +170,8 @@ int test_main() std::vector tmp; std::back_insert_iterator > out(tmp); bencode(out, t.generate()); - boost::intrusive_ptr info(new torrent_info(&tmp[0], tmp.size())); + error_code ec; + boost::intrusive_ptr info(new torrent_info(&tmp[0], tmp.size(), ec)); test_running_torrent(info, 0); } diff --git a/test/test_trackers_extension.cpp b/test/test_trackers_extension.cpp index 6b4615085..fcd57e618 100644 --- a/test/test_trackers_extension.cpp +++ b/test/test_trackers_extension.cpp @@ -55,9 +55,10 @@ int test_main() add_torrent_params atp; atp.info_hash = sha1_hash("12345678901234567890"); atp.save_path = "./"; - torrent_handle tor1 = ses1.add_torrent(atp); + error_code ec; + torrent_handle tor1 = ses1.add_torrent(atp, ec); atp.tracker_url = "http://test.non-existent.com/announce"; - torrent_handle tor2 = ses2.add_torrent(atp); + torrent_handle tor2 = ses2.add_torrent(atp, ec); tor2.connect_peer(tcp::endpoint(address_v4::from_string("127.0.0.1"), ses1.listen_port())); for (int i = 0; i < 130; ++i) diff --git a/test/test_transfer.cpp b/test/test_transfer.cpp index 66f40a813..5b46ab4ee 100644 --- a/test/test_transfer.cpp +++ b/test/test_transfer.cpp @@ -43,6 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "test.hpp" #include "setup_transfer.hpp" #include +#include using namespace libtorrent; using boost::tuples::ignore; @@ -399,7 +400,7 @@ void test_transfer(bool test_disk_full = false, bool test_allowed_fast = false) p.ti = t; p.save_path = "./tmp2_transfer_moved"; p.resume_data = &resume_data; - tor2 = ses2.add_torrent(p); + tor2 = ses2.add_torrent(p, ec); ses2.set_alert_mask(alert::all_categories & ~alert::progress_notification); tor2.prioritize_pieces(priorities); std::cout << "resetting priorities" << std::endl; diff --git a/test/test_upnp.cpp b/test/test_upnp.cpp index a891acdfb..0504a2738 100644 --- a/test/test_upnp.cpp +++ b/test/test_upnp.cpp @@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include using namespace libtorrent; @@ -145,7 +146,8 @@ void incoming_msearch(udp::endpoint const& from, char* buffer p.incoming(buffer::const_interval(buffer, buffer + size), error); if (error || !p.header_finished()) { - std::cerr << "*** malformed HTTP from " << from << std::endl; + std::cerr << "*** malformed HTTP from " + << print_endpoint(from) << std::endl; return; } diff --git a/test/test_web_seed.cpp b/test/test_web_seed.cpp index 9e403fb8d..3b79153cb 100644 --- a/test/test_web_seed.cpp +++ b/test/test_web_seed.cpp @@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/thread.hpp" #include #include +#include #include "test.hpp" #include "setup_transfer.hpp" @@ -77,7 +78,7 @@ void test_transfer(boost::intrusive_ptr torrent_file, int proxy) ses.set_web_seed_proxy(ps); } - torrent_handle th = ses.add_torrent(*torrent_file, "./tmp2_web_seed"); + torrent_handle th = ses.add_torrent(*torrent_file, "./tmp2_web_seed", ec); std::vector empty; th.replace_trackers(empty); @@ -170,7 +171,7 @@ int test_main() start_web_server(8000); // calculate the hash for all pieces - set_piece_hashes(t, "./tmp1_web_seed"); + set_piece_hashes(t, "./tmp1_web_seed", ec); boost::intrusive_ptr torrent_file(new torrent_info(t.generate())); for (int i = 0; i < 6; ++i)