forked from premiere/premiere-libtorrent
make tests not depend on exceptions
This commit is contained in:
parent
19660306e0
commit
c6b793021d
|
@ -31,6 +31,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
int test_main();
|
int test_main();
|
||||||
|
|
||||||
|
|
|
@ -309,7 +309,8 @@ setup_transfer(session* ses1, session* ses2, session* ses3
|
||||||
if (connect_peers)
|
if (connect_peers)
|
||||||
{
|
{
|
||||||
std::cerr << "connecting peer\n";
|
std::cerr << "connecting peer\n";
|
||||||
tor1.connect_peer(tcp::endpoint(address::from_string("127.0.0.1")
|
error_code ec;
|
||||||
|
tor1.connect_peer(tcp::endpoint(address::from_string("127.0.0.1", ec)
|
||||||
, ses2->listen_port()));
|
, ses2->listen_port()));
|
||||||
|
|
||||||
if (ses3)
|
if (ses3)
|
||||||
|
@ -317,10 +318,10 @@ setup_transfer(session* ses1, session* ses2, session* ses3
|
||||||
// give the other peers some time to get an initial
|
// give the other peers some time to get an initial
|
||||||
// set of pieces before they start sharing with each-other
|
// set of pieces before they start sharing with each-other
|
||||||
tor3.connect_peer(tcp::endpoint(
|
tor3.connect_peer(tcp::endpoint(
|
||||||
address::from_string("127.0.0.1")
|
address::from_string("127.0.0.1", ec)
|
||||||
, ses2->listen_port()));
|
, ses2->listen_port()));
|
||||||
tor3.connect_peer(tcp::endpoint(
|
tor3.connect_peer(tcp::endpoint(
|
||||||
address::from_string("127.0.0.1")
|
address::from_string("127.0.0.1", ec)
|
||||||
, ses1->listen_port()));
|
, ses1->listen_port()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,14 +280,16 @@ void do_tick(error_code const&e, deadline_timer& tick, connections_t& v)
|
||||||
}
|
}
|
||||||
std::for_each(v.begin(), v.end()
|
std::for_each(v.begin(), v.end()
|
||||||
, boost::bind(&peer_connection::tick, _1));
|
, boost::bind(&peer_connection::tick, _1));
|
||||||
tick.expires_from_now(seconds(1));
|
error_code ec;
|
||||||
|
tick.expires_from_now(seconds(1), ec);
|
||||||
tick.async_wait(boost::bind(&do_tick, _1, boost::ref(tick), boost::ref(v)));
|
tick.async_wait(boost::bind(&do_tick, _1, boost::ref(tick), boost::ref(v)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_stop(deadline_timer& tick, connections_t& v)
|
void do_stop(deadline_timer& tick, connections_t& v)
|
||||||
{
|
{
|
||||||
abort_tick = true;
|
abort_tick = true;
|
||||||
tick.cancel();
|
error_code ec;
|
||||||
|
tick.cancel(ec);
|
||||||
std::for_each(v.begin(), v.end()
|
std::for_each(v.begin(), v.end()
|
||||||
, boost::bind(&peer_connection::stop, _1));
|
, boost::bind(&peer_connection::stop, _1));
|
||||||
std::cerr << " stopping..." << std::endl;
|
std::cerr << " stopping..." << std::endl;
|
||||||
|
@ -312,7 +314,8 @@ void do_change_rate(error_code const&e, deadline_timer& tick
|
||||||
t1->m_bandwidth_limit[0].throttle(limit + limit / 2 * ((counter & 1)?-1:1));
|
t1->m_bandwidth_limit[0].throttle(limit + limit / 2 * ((counter & 1)?-1:1));
|
||||||
t2->m_bandwidth_limit[0].throttle(limit + limit / 2 * ((counter & 1)?1:-1));
|
t2->m_bandwidth_limit[0].throttle(limit + limit / 2 * ((counter & 1)?1:-1));
|
||||||
|
|
||||||
tick.expires_from_now(milliseconds(1600));
|
error_code ec;
|
||||||
|
tick.expires_from_now(milliseconds(1600), ec);
|
||||||
tick.async_wait(boost::bind(&do_change_rate, _1, boost::ref(tick), t1, t2, limit, counter-1));
|
tick.async_wait(boost::bind(&do_change_rate, _1, boost::ref(tick), t1, t2, limit, counter-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,7 +338,8 @@ void do_change_peer_rate(error_code const&e, deadline_timer& tick
|
||||||
for (connections_t::iterator i = v.begin(); i != v.end(); ++i, ++c)
|
for (connections_t::iterator i = v.begin(); i != v.end(); ++i, ++c)
|
||||||
i->get()->throttle(limit + limit / 2 * ((c & 1)?-1:1));
|
i->get()->throttle(limit + limit / 2 * ((c & 1)?-1:1));
|
||||||
|
|
||||||
tick.expires_from_now(milliseconds(1100));
|
error_code ec;
|
||||||
|
tick.expires_from_now(milliseconds(1100), ec);
|
||||||
tick.async_wait(boost::bind(&do_change_peer_rate, _1, boost::ref(tick), boost::ref(v), limit, counter-1));
|
tick.async_wait(boost::bind(&do_change_peer_rate, _1, boost::ref(tick), boost::ref(v), limit, counter-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,17 +348,19 @@ void run_test(io_service& ios, connections_t& v)
|
||||||
abort_tick = false;
|
abort_tick = false;
|
||||||
std::cerr << "-------------" << std::endl;
|
std::cerr << "-------------" << std::endl;
|
||||||
deadline_timer tick(ios);
|
deadline_timer tick(ios);
|
||||||
tick.expires_from_now(seconds(1));
|
|
||||||
|
error_code ec;
|
||||||
|
tick.expires_from_now(seconds(1), ec);
|
||||||
tick.async_wait(boost::bind(&do_tick, _1, boost::ref(tick), boost::ref(v)));
|
tick.async_wait(boost::bind(&do_tick, _1, boost::ref(tick), boost::ref(v)));
|
||||||
|
|
||||||
deadline_timer complete(ios);
|
deadline_timer complete(ios);
|
||||||
complete.expires_from_now(milliseconds(int(sample_time * 1000)));
|
complete.expires_from_now(milliseconds(int(sample_time * 1000)), ec);
|
||||||
complete.async_wait(boost::bind(&do_stop, boost::ref(tick), boost::ref(v)));
|
complete.async_wait(boost::bind(&do_stop, boost::ref(tick), boost::ref(v)));
|
||||||
|
|
||||||
std::for_each(v.begin(), v.end()
|
std::for_each(v.begin(), v.end()
|
||||||
, boost::bind(&peer_connection::start, _1));
|
, boost::bind(&peer_connection::start, _1));
|
||||||
|
|
||||||
ios.run();
|
ios.run(ec);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool close_to(float val, float comp, float err)
|
bool close_to(float val, float comp, float err)
|
||||||
|
@ -420,8 +426,9 @@ void test_connections_variable_rate(int num, int limit, int torrent_limit)
|
||||||
std::for_each(v.begin(), v.end()
|
std::for_each(v.begin(), v.end()
|
||||||
, boost::bind(&peer_connection::throttle, _1, limit));
|
, boost::bind(&peer_connection::throttle, _1, limit));
|
||||||
|
|
||||||
|
error_code ec;
|
||||||
deadline_timer change_rate(ios);
|
deadline_timer change_rate(ios);
|
||||||
change_rate.expires_from_now(milliseconds(1600));
|
change_rate.expires_from_now(milliseconds(1600), ec);
|
||||||
change_rate.async_wait(boost::bind(&do_change_peer_rate, _1, boost::ref(change_rate)
|
change_rate.async_wait(boost::bind(&do_change_peer_rate, _1, boost::ref(change_rate)
|
||||||
, boost::ref(v), limit, 9));
|
, boost::ref(v), limit, 9));
|
||||||
run_test(ios, v);
|
run_test(ios, v);
|
||||||
|
@ -552,8 +559,9 @@ void test_torrents_variable_rate(int num, int limit, int global_limit)
|
||||||
std::copy(v1.begin(), v1.end(), std::back_inserter(v));
|
std::copy(v1.begin(), v1.end(), std::back_inserter(v));
|
||||||
std::copy(v2.begin(), v2.end(), std::back_inserter(v));
|
std::copy(v2.begin(), v2.end(), std::back_inserter(v));
|
||||||
|
|
||||||
|
error_code ec;
|
||||||
deadline_timer change_rate(ios);
|
deadline_timer change_rate(ios);
|
||||||
change_rate.expires_from_now(milliseconds(1100));
|
change_rate.expires_from_now(milliseconds(1100), ec);
|
||||||
change_rate.async_wait(boost::bind(&do_change_rate, _1, boost::ref(change_rate), t1, t2, limit, 9));
|
change_rate.async_wait(boost::bind(&do_change_rate, _1, boost::ref(change_rate), t1, t2, limit, 9));
|
||||||
|
|
||||||
run_test(ios, v);
|
run_test(ios, v);
|
||||||
|
|
|
@ -168,7 +168,8 @@ void test_reject_fast()
|
||||||
|
|
||||||
io_service ios;
|
io_service ios;
|
||||||
stream_socket s(ios);
|
stream_socket s(ios);
|
||||||
s.connect(tcp::endpoint(address::from_string("127.0.0.1"), ses1.listen_port()));
|
error_code ec;
|
||||||
|
s.connect(tcp::endpoint(address::from_string("127.0.0.1", ec), ses1.listen_port()), ec);
|
||||||
|
|
||||||
char recv_buffer[1000];
|
char recv_buffer[1000];
|
||||||
do_handshake(s, ih, recv_buffer);
|
do_handshake(s, ih, recv_buffer);
|
||||||
|
@ -230,8 +231,9 @@ void test_respect_suggest()
|
||||||
test_sleep(2000);
|
test_sleep(2000);
|
||||||
|
|
||||||
io_service ios;
|
io_service ios;
|
||||||
|
error_code ec;
|
||||||
stream_socket s(ios);
|
stream_socket s(ios);
|
||||||
s.connect(tcp::endpoint(address::from_string("127.0.0.1"), ses1.listen_port()));
|
s.connect(tcp::endpoint(address::from_string("127.0.0.1", ec), ses1.listen_port()), ec);
|
||||||
|
|
||||||
char recv_buffer[1000];
|
char recv_buffer[1000];
|
||||||
do_handshake(s, ih, recv_buffer);
|
do_handshake(s, ih, recv_buffer);
|
||||||
|
|
|
@ -66,8 +66,9 @@ void http_connect_handler(http_connection& c)
|
||||||
{
|
{
|
||||||
++connect_handler_called;
|
++connect_handler_called;
|
||||||
TEST_CHECK(c.socket().is_open());
|
TEST_CHECK(c.socket().is_open());
|
||||||
std::cerr << "connected to: " << c.socket().remote_endpoint() << std::endl;
|
error_code ec;
|
||||||
TEST_CHECK(c.socket().remote_endpoint().address() == address::from_string("127.0.0.1"));
|
std::cerr << "connected to: " << c.socket().remote_endpoint(ec) << std::endl;
|
||||||
|
TEST_CHECK(c.socket().remote_endpoint(ec).address() == address::from_string("127.0.0.1", ec));
|
||||||
}
|
}
|
||||||
|
|
||||||
void http_handler(error_code const& ec, http_parser const& parser
|
void http_handler(error_code const& ec, http_parser const& parser
|
||||||
|
@ -110,7 +111,8 @@ void run_test(std::string const& url, int size, int status, int connected
|
||||||
, &::http_handler, true, &::http_connect_handler));
|
, &::http_handler, true, &::http_connect_handler));
|
||||||
h->get(url, seconds(5), 0, &ps);
|
h->get(url, seconds(5), 0, &ps);
|
||||||
ios.reset();
|
ios.reset();
|
||||||
ios.run();
|
error_code e;
|
||||||
|
ios.run(e);
|
||||||
|
|
||||||
std::cerr << "connect_handler_called: " << connect_handler_called << std::endl;
|
std::cerr << "connect_handler_called: " << connect_handler_called << std::endl;
|
||||||
std::cerr << "handler_called: " << handler_called << std::endl;
|
std::cerr << "handler_called: " << handler_called << std::endl;
|
||||||
|
|
|
@ -56,14 +56,18 @@ bool compare(ip_range<Addr> const& lhs
|
||||||
&& lhs.flags == rhs.flags;
|
&& lhs.flags == rhs.flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define IP(x) address::from_string(x, ec)
|
||||||
|
#define IP4(x) address_v4::from_string(x, ec)
|
||||||
|
|
||||||
void test_rules_invariant(std::vector<ip_range<address_v4> > const& r, ip_filter const& f)
|
void test_rules_invariant(std::vector<ip_range<address_v4> > const& r, ip_filter const& f)
|
||||||
{
|
{
|
||||||
typedef std::vector<ip_range<address_v4> >::const_iterator iterator;
|
typedef std::vector<ip_range<address_v4> >::const_iterator iterator;
|
||||||
TEST_CHECK(!r.empty());
|
TEST_CHECK(!r.empty());
|
||||||
if (r.empty()) return;
|
if (r.empty()) return;
|
||||||
|
|
||||||
TEST_CHECK(r.front().first == address::from_string("0.0.0.0"));
|
error_code ec;
|
||||||
TEST_CHECK(r.back().last == address::from_string("255.255.255.255"));
|
TEST_CHECK(r.front().first == IP("0.0.0.0"));
|
||||||
|
TEST_CHECK(r.back().last == IP("255.255.255.255"));
|
||||||
|
|
||||||
iterator i = r.begin();
|
iterator i = r.begin();
|
||||||
iterator j = boost::next(i);
|
iterator j = boost::next(i);
|
||||||
|
@ -81,19 +85,20 @@ int test_main()
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
|
||||||
std::vector<ip_range<address_v4> > range;
|
std::vector<ip_range<address_v4> > range;
|
||||||
|
error_code ec;
|
||||||
|
|
||||||
// **** test joining of ranges at the end ****
|
// **** test joining of ranges at the end ****
|
||||||
ip_range<address_v4> expected1[] =
|
ip_range<address_v4> expected1[] =
|
||||||
{
|
{
|
||||||
{address_v4::from_string("0.0.0.0"), address_v4::from_string("0.255.255.255"), 0}
|
{IP4("0.0.0.0"), IP4("0.255.255.255"), 0}
|
||||||
, {address_v4::from_string("1.0.0.0"), address_v4::from_string("3.0.0.0"), ip_filter::blocked}
|
, {IP4("1.0.0.0"), IP4("3.0.0.0"), ip_filter::blocked}
|
||||||
, {address_v4::from_string("3.0.0.1"), address_v4::from_string("255.255.255.255"), 0}
|
, {IP4("3.0.0.1"), IP4("255.255.255.255"), 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
ip_filter f;
|
ip_filter f;
|
||||||
f.add_rule(address::from_string("1.0.0.0"), address::from_string("2.0.0.0"), ip_filter::blocked);
|
f.add_rule(IP("1.0.0.0"), IP("2.0.0.0"), ip_filter::blocked);
|
||||||
f.add_rule(address::from_string("2.0.0.1"), address::from_string("3.0.0.0"), ip_filter::blocked);
|
f.add_rule(IP("2.0.0.1"), IP("3.0.0.0"), ip_filter::blocked);
|
||||||
|
|
||||||
range = boost::get<0>(f.export_filter());
|
range = boost::get<0>(f.export_filter());
|
||||||
test_rules_invariant(range, f);
|
test_rules_invariant(range, f);
|
||||||
|
@ -107,8 +112,8 @@ int test_main()
|
||||||
|
|
||||||
{
|
{
|
||||||
ip_filter f;
|
ip_filter f;
|
||||||
f.add_rule(address::from_string("2.0.0.1"), address::from_string("3.0.0.0"), ip_filter::blocked);
|
f.add_rule(IP("2.0.0.1"), IP("3.0.0.0"), ip_filter::blocked);
|
||||||
f.add_rule(address::from_string("1.0.0.0"), address::from_string("2.0.0.0"), ip_filter::blocked);
|
f.add_rule(IP("1.0.0.0"), IP("2.0.0.0"), ip_filter::blocked);
|
||||||
|
|
||||||
range = boost::get<0>(f.export_filter());
|
range = boost::get<0>(f.export_filter());
|
||||||
test_rules_invariant(range, f);
|
test_rules_invariant(range, f);
|
||||||
|
@ -123,8 +128,8 @@ int test_main()
|
||||||
|
|
||||||
{
|
{
|
||||||
ip_filter f;
|
ip_filter f;
|
||||||
f.add_rule(address::from_string("2.0.0.1"), address::from_string("3.0.0.0"), ip_filter::blocked);
|
f.add_rule(IP("2.0.0.1"), IP("3.0.0.0"), ip_filter::blocked);
|
||||||
f.add_rule(address::from_string("1.0.0.0"), address::from_string("2.4.0.0"), ip_filter::blocked);
|
f.add_rule(IP("1.0.0.0"), IP("2.4.0.0"), ip_filter::blocked);
|
||||||
|
|
||||||
range = boost::get<0>(f.export_filter());
|
range = boost::get<0>(f.export_filter());
|
||||||
test_rules_invariant(range, f);
|
test_rules_invariant(range, f);
|
||||||
|
@ -139,8 +144,8 @@ int test_main()
|
||||||
|
|
||||||
{
|
{
|
||||||
ip_filter f;
|
ip_filter f;
|
||||||
f.add_rule(address::from_string("1.0.0.0"), address::from_string("2.4.0.0"), ip_filter::blocked);
|
f.add_rule(IP("1.0.0.0"), IP("2.4.0.0"), ip_filter::blocked);
|
||||||
f.add_rule(address::from_string("2.0.0.1"), address::from_string("3.0.0.0"), ip_filter::blocked);
|
f.add_rule(IP("2.0.0.1"), IP("3.0.0.0"), ip_filter::blocked);
|
||||||
|
|
||||||
range = boost::get<0>(f.export_filter());
|
range = boost::get<0>(f.export_filter());
|
||||||
test_rules_invariant(range, f);
|
test_rules_invariant(range, f);
|
||||||
|
@ -155,12 +160,12 @@ int test_main()
|
||||||
|
|
||||||
{
|
{
|
||||||
ip_filter f;
|
ip_filter f;
|
||||||
f.add_rule(address::from_string("1.0.0.0"), address::from_string("2.0.0.0"), ip_filter::blocked);
|
f.add_rule(IP("1.0.0.0"), IP("2.0.0.0"), ip_filter::blocked);
|
||||||
f.add_rule(address::from_string("3.0.0.0"), address::from_string("4.0.0.0"), ip_filter::blocked);
|
f.add_rule(IP("3.0.0.0"), IP("4.0.0.0"), ip_filter::blocked);
|
||||||
f.add_rule(address::from_string("5.0.0.0"), address::from_string("6.0.0.0"), ip_filter::blocked);
|
f.add_rule(IP("5.0.0.0"), IP("6.0.0.0"), ip_filter::blocked);
|
||||||
f.add_rule(address::from_string("7.0.0.0"), address::from_string("8.0.0.0"), ip_filter::blocked);
|
f.add_rule(IP("7.0.0.0"), IP("8.0.0.0"), ip_filter::blocked);
|
||||||
|
|
||||||
f.add_rule(address::from_string("1.0.1.0"), address::from_string("9.0.0.0"), ip_filter::blocked);
|
f.add_rule(IP("1.0.1.0"), IP("9.0.0.0"), ip_filter::blocked);
|
||||||
|
|
||||||
range = boost::get<0>(f.export_filter());
|
range = boost::get<0>(f.export_filter());
|
||||||
test_rules_invariant(range, f);
|
test_rules_invariant(range, f);
|
||||||
|
@ -168,9 +173,9 @@ int test_main()
|
||||||
TEST_CHECK(range.size() == 3);
|
TEST_CHECK(range.size() == 3);
|
||||||
ip_range<address_v4> expected[] =
|
ip_range<address_v4> expected[] =
|
||||||
{
|
{
|
||||||
{address_v4::from_string("0.0.0.0"), address_v4::from_string("0.255.255.255"), 0}
|
{IP4("0.0.0.0"), IP4("0.255.255.255"), 0}
|
||||||
, {address_v4::from_string("1.0.0.0"), address_v4::from_string("9.0.0.0"), ip_filter::blocked}
|
, {IP4("1.0.0.0"), IP4("9.0.0.0"), ip_filter::blocked}
|
||||||
, {address_v4::from_string("9.0.0.1"), address_v4::from_string("255.255.255.255"), 0}
|
, {IP4("9.0.0.1"), IP4("255.255.255.255"), 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_CHECK(std::equal(range.begin(), range.end(), expected, &compare<address_v4>));
|
TEST_CHECK(std::equal(range.begin(), range.end(), expected, &compare<address_v4>));
|
||||||
|
@ -181,12 +186,12 @@ int test_main()
|
||||||
|
|
||||||
{
|
{
|
||||||
ip_filter f;
|
ip_filter f;
|
||||||
f.add_rule(address::from_string("1.0.0.0"), address::from_string("2.0.0.0"), ip_filter::blocked);
|
f.add_rule(IP("1.0.0.0"), IP("2.0.0.0"), ip_filter::blocked);
|
||||||
f.add_rule(address::from_string("3.0.0.0"), address::from_string("4.0.0.0"), ip_filter::blocked);
|
f.add_rule(IP("3.0.0.0"), IP("4.0.0.0"), ip_filter::blocked);
|
||||||
f.add_rule(address::from_string("5.0.0.0"), address::from_string("6.0.0.0"), ip_filter::blocked);
|
f.add_rule(IP("5.0.0.0"), IP("6.0.0.0"), ip_filter::blocked);
|
||||||
f.add_rule(address::from_string("7.0.0.0"), address::from_string("8.0.0.0"), ip_filter::blocked);
|
f.add_rule(IP("7.0.0.0"), IP("8.0.0.0"), ip_filter::blocked);
|
||||||
|
|
||||||
f.add_rule(address::from_string("0.0.1.0"), address::from_string("7.0.4.0"), ip_filter::blocked);
|
f.add_rule(IP("0.0.1.0"), IP("7.0.4.0"), ip_filter::blocked);
|
||||||
|
|
||||||
range = boost::get<0>(f.export_filter());
|
range = boost::get<0>(f.export_filter());
|
||||||
test_rules_invariant(range, f);
|
test_rules_invariant(range, f);
|
||||||
|
@ -194,9 +199,9 @@ int test_main()
|
||||||
TEST_CHECK(range.size() == 3);
|
TEST_CHECK(range.size() == 3);
|
||||||
ip_range<address_v4> expected[] =
|
ip_range<address_v4> expected[] =
|
||||||
{
|
{
|
||||||
{address_v4::from_string("0.0.0.0"), address_v4::from_string("0.0.0.255"), 0}
|
{IP4("0.0.0.0"), IP4("0.0.0.255"), 0}
|
||||||
, {address_v4::from_string("0.0.1.0"), address_v4::from_string("8.0.0.0"), ip_filter::blocked}
|
, {IP4("0.0.1.0"), IP4("8.0.0.0"), ip_filter::blocked}
|
||||||
, {address_v4::from_string("8.0.0.1"), address_v4::from_string("255.255.255.255"), 0}
|
, {IP4("8.0.0.1"), IP4("255.255.255.255"), 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_CHECK(std::equal(range.begin(), range.end(), expected, &compare<address_v4>));
|
TEST_CHECK(std::equal(range.begin(), range.end(), expected, &compare<address_v4>));
|
||||||
|
|
|
@ -31,25 +31,26 @@ int main(int argc, char* argv[])
|
||||||
int tcp_map = natpmp_handler->add_mapping(natpmp::tcp, atoi(argv[1]), atoi(argv[1]));
|
int tcp_map = natpmp_handler->add_mapping(natpmp::tcp, atoi(argv[1]), atoi(argv[1]));
|
||||||
int udp_map = natpmp_handler->add_mapping(natpmp::udp, atoi(argv[2]), atoi(argv[2]));
|
int udp_map = natpmp_handler->add_mapping(natpmp::udp, atoi(argv[2]), atoi(argv[2]));
|
||||||
|
|
||||||
timer.expires_from_now(seconds(2));
|
error_code ec;
|
||||||
|
timer.expires_from_now(seconds(2), ec);
|
||||||
timer.async_wait(boost::bind(&io_service::stop, boost::ref(ios)));
|
timer.async_wait(boost::bind(&io_service::stop, boost::ref(ios)));
|
||||||
std::cerr << "mapping ports TCP: " << argv[1]
|
std::cerr << "mapping ports TCP: " << argv[1]
|
||||||
<< " UDP: " << argv[2] << std::endl;
|
<< " UDP: " << argv[2] << std::endl;
|
||||||
|
|
||||||
ios.reset();
|
ios.reset();
|
||||||
ios.run();
|
ios.run(ec);
|
||||||
timer.expires_from_now(seconds(2));
|
timer.expires_from_now(seconds(2), ec);
|
||||||
timer.async_wait(boost::bind(&io_service::stop, boost::ref(ios)));
|
timer.async_wait(boost::bind(&io_service::stop, boost::ref(ios)));
|
||||||
std::cerr << "removing mapping " << tcp_map << std::endl;
|
std::cerr << "removing mapping " << tcp_map << std::endl;
|
||||||
natpmp_handler->delete_mapping(tcp_map);
|
natpmp_handler->delete_mapping(tcp_map);
|
||||||
|
|
||||||
ios.reset();
|
ios.reset();
|
||||||
ios.run();
|
ios.run(ec);
|
||||||
std::cerr << "removing mappings" << std::endl;
|
std::cerr << "removing mappings" << std::endl;
|
||||||
natpmp_handler->close();
|
natpmp_handler->close();
|
||||||
|
|
||||||
ios.reset();
|
ios.reset();
|
||||||
ios.run();
|
ios.run(ec);
|
||||||
std::cerr << "closing" << std::endl;
|
std::cerr << "closing" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,8 +90,9 @@ void test_pex()
|
||||||
|
|
||||||
test_sleep(1000);
|
test_sleep(1000);
|
||||||
|
|
||||||
tor2.connect_peer(tcp::endpoint(address::from_string("127.0.0.1"), ses1.listen_port()));
|
error_code ec;
|
||||||
tor2.connect_peer(tcp::endpoint(address::from_string("127.0.0.1"), ses3.listen_port()));
|
tor2.connect_peer(tcp::endpoint(address::from_string("127.0.0.1", ec), ses1.listen_port()));
|
||||||
|
tor2.connect_peer(tcp::endpoint(address::from_string("127.0.0.1", ec), ses3.listen_port()));
|
||||||
|
|
||||||
for (int i = 0; i < 90; ++i)
|
for (int i = 0; i < 90; ++i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -156,19 +156,20 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
|
||||||
, test_path, fp, io, default_storage_constructor, storage_mode);
|
, test_path, fp, io, default_storage_constructor, storage_mode);
|
||||||
boost::mutex lock;
|
boost::mutex lock;
|
||||||
|
|
||||||
|
error_code ec;
|
||||||
lazy_entry frd;
|
lazy_entry frd;
|
||||||
pm->async_check_fastresume(&frd, &on_check_resume_data);
|
pm->async_check_fastresume(&frd, &on_check_resume_data);
|
||||||
ios.reset();
|
ios.reset();
|
||||||
ios.run();
|
ios.run(ec);
|
||||||
|
|
||||||
pm->async_check_files(&on_check_files);
|
pm->async_check_files(&on_check_files);
|
||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
ios.reset();
|
ios.reset();
|
||||||
ios.run_one();
|
ios.run_one(ec);
|
||||||
}
|
}
|
||||||
ios.reset();
|
ios.reset();
|
||||||
ios.poll();
|
ios.poll(ec);
|
||||||
|
|
||||||
// test move_storage
|
// test move_storage
|
||||||
boost::function<void(int, disk_io_job const&)> none;
|
boost::function<void(int, disk_io_job const&)> none;
|
||||||
|
@ -177,7 +178,7 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
|
||||||
|
|
||||||
test_sleep(2000);
|
test_sleep(2000);
|
||||||
ios.reset();
|
ios.reset();
|
||||||
ios.poll();
|
ios.poll(ec);
|
||||||
|
|
||||||
TEST_CHECK(!exists(test_path / "temp_storage"));
|
TEST_CHECK(!exists(test_path / "temp_storage"));
|
||||||
TEST_CHECK(exists(test_path / "temp_storage2/temp_storage"));
|
TEST_CHECK(exists(test_path / "temp_storage2/temp_storage"));
|
||||||
|
@ -185,7 +186,7 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
|
||||||
|
|
||||||
test_sleep(2000);
|
test_sleep(2000);
|
||||||
ios.reset();
|
ios.reset();
|
||||||
ios.poll();
|
ios.poll(ec);
|
||||||
|
|
||||||
TEST_CHECK(!exists(test_path / "temp_storage2/temp_storage"));
|
TEST_CHECK(!exists(test_path / "temp_storage2/temp_storage"));
|
||||||
remove_all(test_path / "temp_storage2");
|
remove_all(test_path / "temp_storage2");
|
||||||
|
@ -198,7 +199,7 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
|
||||||
|
|
||||||
test_sleep(2000);
|
test_sleep(2000);
|
||||||
ios.reset();
|
ios.reset();
|
||||||
ios.poll();
|
ios.poll(ec);
|
||||||
|
|
||||||
TEST_CHECK(!exists(test_path / "temp_storage/test1.tmp"));
|
TEST_CHECK(!exists(test_path / "temp_storage/test1.tmp"));
|
||||||
TEST_CHECK(exists(test_path / "part0"));
|
TEST_CHECK(exists(test_path / "part0"));
|
||||||
|
@ -218,7 +219,7 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
|
||||||
test_sleep(1000);
|
test_sleep(1000);
|
||||||
TEST_CHECK(!exists(test_path / "part0"));
|
TEST_CHECK(!exists(test_path / "part0"));
|
||||||
|
|
||||||
ios.run();
|
ios.run(ec);
|
||||||
|
|
||||||
io.join();
|
io.join();
|
||||||
}
|
}
|
||||||
|
@ -312,10 +313,11 @@ void test_check_files(path const& test_path
|
||||||
, test_path, fp, io, default_storage_constructor, storage_mode);
|
, test_path, fp, io, default_storage_constructor, storage_mode);
|
||||||
boost::mutex lock;
|
boost::mutex lock;
|
||||||
|
|
||||||
|
error_code ec;
|
||||||
lazy_entry frd;
|
lazy_entry frd;
|
||||||
pm->async_check_fastresume(&frd, &on_check_resume_data);
|
pm->async_check_fastresume(&frd, &on_check_resume_data);
|
||||||
ios.reset();
|
ios.reset();
|
||||||
ios.run();
|
ios.run(ec);
|
||||||
|
|
||||||
bool pieces[4] = {false, false, false, false};
|
bool pieces[4] = {false, false, false, false};
|
||||||
bool done = false;
|
bool done = false;
|
||||||
|
@ -324,7 +326,7 @@ void test_check_files(path const& test_path
|
||||||
while (!done)
|
while (!done)
|
||||||
{
|
{
|
||||||
ios.reset();
|
ios.reset();
|
||||||
ios.run_one();
|
ios.run_one(ec);
|
||||||
}
|
}
|
||||||
TEST_CHECK(pieces[0] == true);
|
TEST_CHECK(pieces[0] == true);
|
||||||
TEST_CHECK(pieces[1] == false);
|
TEST_CHECK(pieces[1] == false);
|
||||||
|
|
|
@ -72,7 +72,7 @@ int main(int argc, char* argv[])
|
||||||
std::cerr << "broadcasting for UPnP device" << std::endl;
|
std::cerr << "broadcasting for UPnP device" << std::endl;
|
||||||
|
|
||||||
ios.reset();
|
ios.reset();
|
||||||
ios.run();
|
ios.run(ec);
|
||||||
|
|
||||||
upnp_handler->add_mapping(upnp::tcp, atoi(argv[1]), atoi(argv[1]));
|
upnp_handler->add_mapping(upnp::tcp, atoi(argv[1]), atoi(argv[1]));
|
||||||
upnp_handler->add_mapping(upnp::udp, atoi(argv[2]), atoi(argv[2]));
|
upnp_handler->add_mapping(upnp::udp, atoi(argv[2]), atoi(argv[2]));
|
||||||
|
@ -82,13 +82,13 @@ int main(int argc, char* argv[])
|
||||||
<< " UDP: " << argv[2] << std::endl;
|
<< " UDP: " << argv[2] << std::endl;
|
||||||
|
|
||||||
ios.reset();
|
ios.reset();
|
||||||
ios.run();
|
ios.run(ec);
|
||||||
std::cerr << "router: " << upnp_handler->router_model() << std::endl;
|
std::cerr << "router: " << upnp_handler->router_model() << std::endl;
|
||||||
std::cerr << "removing mappings" << std::endl;
|
std::cerr << "removing mappings" << std::endl;
|
||||||
upnp_handler->close();
|
upnp_handler->close();
|
||||||
|
|
||||||
ios.reset();
|
ios.reset();
|
||||||
ios.run();
|
ios.run(ec);
|
||||||
std::cerr << "closing" << std::endl;
|
std::cerr << "closing" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue