increase the maximum buffer size on bottled http_requests
This commit is contained in:
parent
f4bd67c320
commit
63501ebe5b
|
@ -201,7 +201,8 @@ namespace libtorrent
|
|||
|
||||
void async_read(
|
||||
peer_request const& r
|
||||
, boost::function<void(int, disk_io_job const&)> const& handler);
|
||||
, boost::function<void(int, disk_io_job const&)> const& handler
|
||||
, char* buffer = 0);
|
||||
|
||||
void async_write(
|
||||
peer_request const& r
|
||||
|
|
|
@ -179,29 +179,35 @@ namespace libtorrent
|
|||
|
||||
int ret = 0;
|
||||
|
||||
bool free_buffer = true;
|
||||
try
|
||||
{
|
||||
// std::cerr << "DISK THREAD: executing job: " << j.action << std::endl;
|
||||
switch (j.action)
|
||||
{
|
||||
case disk_io_job::read:
|
||||
l.lock();
|
||||
j.buffer = (char*)m_pool.ordered_malloc();
|
||||
l.unlock();
|
||||
if (j.buffer == 0)
|
||||
{
|
||||
ret = -1;
|
||||
j.str = "out of memory";
|
||||
l.lock();
|
||||
j.buffer = (char*)m_pool.ordered_malloc();
|
||||
l.unlock();
|
||||
assert(j.buffer_size <= m_block_size);
|
||||
if (j.buffer == 0)
|
||||
{
|
||||
ret = -1;
|
||||
j.str = "out of memory";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(j.buffer_size <= m_block_size);
|
||||
ret = j.storage->read_impl(j.buffer, j.piece, j.offset
|
||||
, j.buffer_size);
|
||||
|
||||
// simulates slow drives
|
||||
// usleep(300);
|
||||
free_buffer = false;
|
||||
}
|
||||
ret = j.storage->read_impl(j.buffer, j.piece, j.offset
|
||||
, j.buffer_size);
|
||||
|
||||
// simulates slow drives
|
||||
// usleep(300);
|
||||
break;
|
||||
case disk_io_job::write:
|
||||
assert(j.buffer);
|
||||
|
@ -240,7 +246,7 @@ namespace libtorrent
|
|||
try { if (handler) handler(ret, j); }
|
||||
catch (std::exception&) {}
|
||||
|
||||
if (j.buffer)
|
||||
if (j.buffer && free_buffer)
|
||||
{
|
||||
l.lock();
|
||||
m_pool.ordered_free(j.buffer);
|
||||
|
@ -249,3 +255,4 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ using boost::bind;
|
|||
namespace libtorrent
|
||||
{
|
||||
|
||||
enum { max_bottled_buffer = 1024 * 1024 };
|
||||
|
||||
void http_connection::get(std::string const& url, time_duration timeout
|
||||
, bool handle_redirect)
|
||||
{
|
||||
|
@ -311,8 +313,8 @@ void http_connection::on_read(asio::error_code const& e
|
|||
}
|
||||
|
||||
if (int(m_recvbuffer.size()) == m_read_pos)
|
||||
m_recvbuffer.resize((std::min)(m_read_pos + 2048, 1024*500));
|
||||
if (m_read_pos == 1024 * 500)
|
||||
m_recvbuffer.resize((std::min)(m_read_pos + 2048, int(max_bottled_buffer)));
|
||||
if (m_read_pos == max_bottled_buffer)
|
||||
{
|
||||
close();
|
||||
if (m_bottled && m_called) return;
|
||||
|
@ -383,3 +385,4 @@ void http_connection::rate_limit(int limit)
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1083,7 +1083,8 @@ namespace libtorrent
|
|||
|
||||
void piece_manager::async_read(
|
||||
peer_request const& r
|
||||
, boost::function<void(int, disk_io_job const&)> const& handler)
|
||||
, boost::function<void(int, disk_io_job const&)> const& handler
|
||||
, char* buffer)
|
||||
{
|
||||
disk_io_job j;
|
||||
j.storage = this;
|
||||
|
@ -1091,7 +1092,10 @@ namespace libtorrent
|
|||
j.piece = r.piece;
|
||||
j.offset = r.start;
|
||||
j.buffer_size = r.length;
|
||||
assert(r.length <= 16 * 1024);
|
||||
j.buffer = buffer;
|
||||
// if a buffer is not specified, only one block can be read
|
||||
// since that is the size of the pool allocator's buffers
|
||||
assert(r.length <= 16 * 1024 || buffer != 0);
|
||||
m_io_thread.add_job(j, handler);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue