fixed bug in web_peer_connection where an incorrect number of bytes would be reported as downloaded

This commit is contained in:
Arvid Norberg
2008-06-03 15:17:09 +00:00
parent c883f4475c
commit b4c160e723
6 changed files with 99 additions and 27 deletions

View File

@@ -25,16 +25,28 @@ using boost::bind;
tuple<int, int, bool> feed_bytes(http_parser& parser, char const* str)
{
tuple<int, int, bool> ret(0, 0, false);
buffer::const_interval recv_buf(str, str + 1);
for (; *str; ++str)
tuple<int, int, bool> prev(0, 0, false);
for (int chunks = 1; chunks < 70; ++chunks)
{
recv_buf.end = str + 1;
int payload, protocol;
bool error = false;
tie(payload, protocol) = parser.incoming(recv_buf, error);
ret.get<0>() += payload;
ret.get<1>() += protocol;
ret.get<2>() += error;
ret = make_tuple(0, 0, false);
parser.reset();
buffer::const_interval recv_buf(str, str);
for (; *str;)
{
int chunk_size = (std::min)(chunks, int(strlen(recv_buf.end)));
if (chunk_size == 0) break;
recv_buf.end += chunk_size;
int payload, protocol;
bool error = false;
tie(payload, protocol) = parser.incoming(recv_buf, error);
ret.get<0>() += payload;
ret.get<1>() += protocol;
ret.get<2>() += error;
std::cerr << payload << ", " << protocol << ", " << chunk_size << std::endl;
TORRENT_ASSERT(payload + protocol == chunk_size);
}
TEST_CHECK(prev == make_tuple(0, 0, false) || ret == prev);
prev = ret;
}
return ret;
}

View File

@@ -21,8 +21,12 @@ void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file, int proxy)
using namespace libtorrent;
session ses;
session_settings settings;
settings.ignore_limits_on_local_network = false;
ses.set_settings(settings);
ses.set_severity_level(alert::debug);
ses.listen_on(std::make_pair(51000, 52000));
ses.set_download_rate_limit(torrent_file->total_size() / 10);
remove_all("./tmp1");
char const* test_name[] = {"no", "SOCKS4", "SOCKS5", "SOCKS5 password", "HTTP", "HTTP password"};
@@ -46,19 +50,44 @@ void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file, int proxy)
std::vector<announce_entry> empty;
th.replace_trackers(empty);
const size_type total_size = torrent_file->total_size();
float rate_sum = 0.f;
float ses_rate_sum = 0.f;
for (int i = 0; i < 30; ++i)
{
torrent_status s = th.status();
std::cerr << s.progress << " " << (s.download_rate / 1000.f) << std::endl;
std::auto_ptr<alert> a;
a = ses.pop_alert();
if (a.get())
std::cerr << a->msg() << "\n";
session_status ss = ses.status();
std::cerr << (s.progress * 100.f) << " %"
<< " torrent rate: " << (s.download_rate / 1000.f) << " kB/s"
<< " session rate: " << (ss.download_rate / 1000.f) << " kB/s"
<< " session total: " << ss.total_payload_download
<< " torrent total: " << s.total_payload_download
<< std::endl;
rate_sum += s.download_payload_rate;
ses_rate_sum += ss.payload_download_rate;
if (th.is_seed()) break;
print_alerts(ses, "ses");
if (th.is_seed() && ss.download_rate == 0.f)
{
TEST_CHECK(ses.status().total_payload_download == total_size);
TEST_CHECK(th.status().total_payload_download == total_size);
break;
}
test_sleep(1000);
}
std::cerr << "total_size: " << total_size
<< " rate_sum: " << rate_sum
<< " session_rate_sum: " << ses_rate_sum
<< std::endl;
// the rates for each second should sum up to the total, with a 10% error margin
TEST_CHECK(fabs(rate_sum - total_size) < total_size * .1f);
TEST_CHECK(fabs(ses_rate_sum - total_size) < total_size * .1f);
TEST_CHECK(th.is_seed());
if (proxy) stop_proxy(8002);