more beos fixes
This commit is contained in:
parent
cebcbc3eeb
commit
96cedc9b5f
@ -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;
|
||||
|
@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <cstring>
|
||||
#include "libtorrent/invariant_check.hpp"
|
||||
#include "libtorrent/assert.hpp"
|
||||
#include <cstdlib> // malloc/free/realloc
|
||||
|
||||
namespace libtorrent {
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -31,7 +31,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#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<peer_disconnected_alert*>(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<fastresume_rejected_alert*>(a.get()) == 0 || allow_failed_fastresume);
|
||||
|
||||
@ -202,7 +202,9 @@ boost::intrusive_ptr<torrent_info> create_torrent(std::ostream* file, int piece_
|
||||
std::back_insert_iterator<std::vector<char> > out(tmp);
|
||||
|
||||
bencode(out, t.generate());
|
||||
return boost::intrusive_ptr<torrent_info>(new torrent_info(&tmp[0], tmp.size()));
|
||||
error_code ec;
|
||||
return boost::intrusive_ptr<torrent_info>(new torrent_info(
|
||||
&tmp[0], tmp.size(), ec));
|
||||
}
|
||||
|
||||
boost::tuple<torrent_handle, torrent_handle, torrent_handle>
|
||||
@ -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()));
|
||||
|
@ -35,6 +35,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
void report_failure(char const* str, char const* file, int line);
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <exception>
|
||||
#include <sstream>
|
||||
|
||||
#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__)
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
|
@ -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 <iostream>
|
||||
|
||||
#include "test.hpp"
|
||||
|
||||
|
@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/io.hpp"
|
||||
#include <cstring>
|
||||
#include <boost/bind.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
@ -161,7 +162,8 @@ void test_reject_fast()
|
||||
boost::intrusive_ptr<torrent_info> 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<torrent_info> 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);
|
||||
|
||||
|
@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "libtorrent/hasher.hpp"
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include "libtorrent/escape_string.hpp" // from_hex
|
||||
|
||||
#include "test.hpp"
|
||||
|
||||
|
@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "setup_transfer.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
#include <iostream>
|
||||
|
||||
void test_lsd()
|
||||
{
|
||||
|
@ -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 <iostream>
|
||||
|
||||
using boost::tuples::ignore;
|
||||
|
||||
|
@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
#include <iostream>
|
||||
|
||||
void test_pex()
|
||||
{
|
||||
|
@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <iostream>
|
||||
|
||||
#include "test.hpp"
|
||||
|
||||
|
@ -52,6 +52,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/tuple/tuple_comparison.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include "test.hpp"
|
||||
|
||||
|
@ -43,6 +43,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
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<torrent_info>(new torrent_info(*t))
|
||||
error_code ec;
|
||||
torrent_handle h = ses.add_torrent(boost::intrusive_ptr<torrent_info>(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<torrent_info>(new torrent_info(*t))
|
||||
torrent_handle h = ses.add_torrent(boost::intrusive_ptr<torrent_info>(new torrent_info(*t, ec))
|
||||
, combine_path(test_path, "tmp2"), entry()
|
||||
, storage_mode_compact);
|
||||
|
||||
|
@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
#include <iostream>
|
||||
|
||||
void test_swarm(bool super_seeding = false, bool strict = false, bool seed_mode = false, bool time_critical = false)
|
||||
{
|
||||
|
@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
@ -52,7 +53,8 @@ void test_running_torrent(boost::intrusive_ptr<torrent_info> 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<char> tmp;
|
||||
std::back_insert_iterator<std::vector<char> > out(tmp);
|
||||
bencode(out, t.generate());
|
||||
boost::intrusive_ptr<torrent_info> info(new torrent_info(&tmp[0], tmp.size()));
|
||||
error_code ec;
|
||||
boost::intrusive_ptr<torrent_info> 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<char> tmp;
|
||||
std::back_insert_iterator<std::vector<char> > out(tmp);
|
||||
bencode(out, t.generate());
|
||||
boost::intrusive_ptr<torrent_info> info(new torrent_info(&tmp[0], tmp.size()));
|
||||
error_code ec;
|
||||
boost::intrusive_ptr<torrent_info> info(new torrent_info(&tmp[0], tmp.size(), ec));
|
||||
test_running_torrent(info, 0);
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -43,6 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
|
@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/intrusive_ptr.hpp>
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
@ -77,7 +78,7 @@ void test_transfer(boost::intrusive_ptr<torrent_info> 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<announce_entry> 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_info> torrent_file(new torrent_info(t.generate()));
|
||||
|
||||
for (int i = 0; i < 6; ++i)
|
||||
|
Loading…
x
Reference in New Issue
Block a user